curl Examples

This topic includes some examples of how to send requests to the Oracle Primavera Cloud Data Service 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 Oracle Primavera Cloud Data Service.

You will need:

  • An Oracle Primavera Cloud user account that has the application administrator privilege
  • The URL of your Oracle Primavera Cloud Data Service RESTful endpoints

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 GET

or

-X POST

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

For example:

curl -X <http-verb> https://<SERVER_URL>/data/rest/dataservice/<endpoint> \
-H "<http-header>:<value>" \
-H "Authorization: Bearer <OAuth-Access-Token>" \
-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 a valid HTTP operation, such as GET or POST.
  • <SERVER_URL> is the server URL where Oracle Primavera Cloud is deployed. For example, primavera.oraclecloud.com.
  • <http-header> is a valid HTTP header. For example, Content-Type.
  • <value> is a valid value for an associated HTTP header. For example, a value for the header Content-Type might be application/json.
  • <endpoint> is a valid data service endpoint, excluding the data service base URL. For example, runquery.
  • <OAuth-Access-Token> is the OAuth access token you generated using Basic Authentication (see note below).
  • <tenant-code> is your Oracle Primavera Cloud tenant code 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 Data Service 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 Data Service API calls.

Example: Get all tables using the tables endpoint

This example command fetches a list of all database tables that are available to use when running a query:

curl -X GET https://<SERVER_URL>/data/rest/dataservice/tables \
-H "Authorization: Bearer <OAuth-Access-Token>" \
-H "x-prime-tenant-code: <tenant-code>" \
-H "<x-param1>: <param1-value>" \
-H "<x-param2>: <param2-value>" \
-H "<x-paramN>: <paramN-value>"

Example: Run a query on specific database table columns using the runquery endpoint

To run a query using the Oracle Primavera Cloud Data Service, you send an HTTP POST request to the /runquery endpoint.

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

In this example, you will query the ACTIVITY_ID, ACTIVITY_NAME, ACTIVITY_TYPE, STATUS, START_DATE, and FINISH_DATE columns in the SM_ACTIVITY table, with criteria PROJ_ID=1 and PLANNED_HOURS >= 1200. To run the query, you will send a POST request to the /data/rest/dataservice/runquery endpoint using data stored in a JSON file named query.json:

curl -X POST -d "@query.json" https://<SERVER_URL>/data/rest/dataservice/runquery \
-H "Authorization: Bearer <OAuth-Access-Token>" \
-H "Content-Type: application/json" \
-H "x-prime-tenant-code: <tenant-code>" \
-H "<x-param1>: <param1-value>" \
-H "<x-param2>: <param2-value>" \
-H "<x-paramN>: <paramN-value>"

The query.json file used in the example above contains the following data:

{
  "name": "My Activities",
  "sinceDate": null,
  "nextTableName": "Activity",
  "nextKey": "1139",
  "tables": [{
    "tableName": "SM_ACTIVITY",
    "columns": [
      "ACTIVITY_ID",
      "ACTIVITY_NAME",
      "ACTIVITY_TYPE",
      "STATUS",
      "START_DATE",
      "FINISH_DATE"
    ],
    "condition": {
      "columnName": null,
      "operator": "AND",
      "value1": null,
      "value2": null,
      "conditions": [{
          "columnName": "PLANNED_HOURS",
          "operator": "GREATER_THAN_OR_EQUALS",
          "value1": "1200",
          "value2": null,
          "conditions": null
        },
        {
          "columnName": "PROJ_ID",
          "operator": "EQUALS",
          "value1": "1",
          "value2": null,
          "conditions": null
        }
      ]
    }
  }]
}