curl Examples

This topic includes some examples of how to send requests to the Oracle Primavera Cloud REST API using curl commands.

Before you begin

1. curl is a third-party command-line tool used for interacting with and testing APIs, and is delivered with Windows 11 and many other operating systems.

To find which version of curl you have installed, open a command prompt and enter:

curl --version

For more information about curl, go to https://curl.se.

2. Contact your account administrator to obtain the account credentials required to manage workspaces using the API.

You will need:

  • An Oracle Primavera Cloud user account
  • The URL of your Oracle Primavera Cloud instance

curl Options

The following table summarizes the curl options used in the examples:

Option Description
-d <json data>

Identifies the request document, in JSON format, on the local machine. For example:

-d @mydatafile.json

-F <form data>

Identifies form data, in JSON format, on the local machine. For example:

-F @myformdatafile.json

-H <http header>:<value>

Defines one or both of the following:

  • Content-Type: Media type of the body of the request
  • Accept: Media type of the body of the request
-i Displays response header information.
-X <http-verb>

Indicates the type of request. For example:

-X DELETE

To use curl to interact with the API, enter the curl command followed by one or more curl options and a valid API endpoint, and any required headers.

For example:

curl -X <http-verb> https://<SERVER_URL>/api/restapi/<endpoint> \
-H "Authorization: Bearer <OAuth-Access-Token>" \
-H "Content-Type: application/json" \
-H "Version: <versionNumber>" \
-H "x-prime-tenant-code: <tenant-code>" \
-H "<x-param1>: <param1-value>" \
-H "<x-param2>: <param2-value>" \
-H "<x-paramN>: <paramN-value>"

Where:

  • <http-verb> is the REST API method of the API. Example: GET, POST, PUT, DELETE.
  • <SERVER_URL> is the server URL where Oracle Primavera Cloud is deployed. For example, primavera.oraclecloud.com.
  • <endpoint> is the name of a valid Oracle Primavera Cloud endpoint, excluding the API base URL. For example, project.
  • <OAuth-Access-Token> is the OAuth access token generated using Basic Authentication or an authorization server (see note below).
  • <versionNumber> is the API version. Providing this is optional; the default is the latest version which is 3.
  • <tenant-code> is the Oracle Primavera Cloud tenant where the data exists (see note below).
  • All the <x-param> and <param-value> pairs represent the additional headers and their values that need to be specified (see note below).

Note:

You can find the values for <OAuth-Access-Token> and <tenant-code>, and also any additional headers and their values, in the OAuth access token generation response. For details, see How Does Primavera Cloud Support Basic Authentication?. For the additional headers, note that all fields under ' requestHeaders' in the access token generation response need to be passed as headers in your Oracle Primavera Cloud API calls.

API Examples

The following examples demonstrate how to use curl to access the Oracle Primavera Cloud API.

To fetch a project object by its project ID

curl -X GET https://<SERVER_URL>/api/restapi/project/5706 \
-H "Authorization: Bearer <OAuth-Access-Token>"

To create a project using this JSON data

API requests that use the POST method require additional data. Pass additional data to curl using the -d option.

The following example sends a POST request to the /project endpoint using data stored in a JSON file named harbour_example.json.

curl -X POST -d "@harbour_example.json" https://<SERVER_URL>/api/restapi/project \
-H "Authorization: Bearer <OAuth-Access-Token>" \
-H "Content-Type: application/json" \
-H "Version: <versionNumber>" \
-H "x-prime-tenant-code: <tenant-code>" \
-H "<x-param1>: <param1-value>" \
-H "<x-param2>: <param2-value>" \
-H "<x-paramN>: <paramN-value>"

Your POST request must include additional JSON data that specifies the project name, parent workspace, and project code. The harbour_example.json file specified in the -d option contains the following:

{
  "projectCode": "EC00610",
  "projectName": "Harbour Pointe Assisted Living Center",
  "workspaceId": 1,
  "planStartDate": "2017-09-01T07:00:00.-0700",
  "status": "ACTIVE",
  "description": "The assisted living center project is a long term project scheduled for completion in 2021 and is a joint venture with ABC Corp.",
  "scheduledFinishDate": "2021-08-31T00:00:00.-0700"
}

Note If the user specified with the curl -u option does not have permission to modify the specified parent workspace, or if the parent workspace does not exist, the project creation will fail, and the API will return a response of 401 or 404.