cURL Overview

Examples within this document demonstrate how to access the Primavera Administration API using cURL.

To access the API with cURL:

  • Install cURL, as described in Using cURL.
  • Start cURL and specify one or more of the command-line options described in this table.

The following table summarizes the cURL options used in the examples in this document:

cURL 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.
-u <username>:<password>

Specifies the username and password for the Primavera Administration account. For example:

-u jsmith:mypassword1

If your username contains a space, you will need to wrap the username text in quotes:

-u "Molly Abraham":mypassword1

-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.

For example:

		curl -u <username>:<password> -H "<http-header>:<value>" -H "Version:<apiVersion>" -X <http-verb> https://<hostName>:<portNumber>/cloudapi/restapi/<service>
		

Command Examples

The following examples demonstrate how to use cURL to access the API.

To fetch a user object by its user ID:

		curl -u jsmith:mypassword1 -H "Accept:application/json" -H "Version:2" -X GET https://localhost:7001/cloudapi/restapi/user/JSMITH
		

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 /user endpoint using data stored in a JSON file named user_example.json. The user_example.json file contains the following:

{"modified": 
      [{ 
          "loginId": "JSMITH", 
          "organization": { 
              "associations": [], 
              "bidderCompany": false, 
              "isDeletable": false,        "inheritedPolicy": false, 
              "displayName": "sfo", 
              "id": "4", 
              "name": "sfo" 
          }, 
          "statusInfo": "", 
          "emailAddress": "jsmith@pgbu.com", 
          "roles": [ 
              { 
                  "displayName": "Primavera Unifier Production", 
                  "id": "77", 
                  "name": "PrimaveraUnifierProduction" 
              } 
          ], 
          "locked": false, 
          "createdBy": "COADMIN", 
          "status": "Active", 
          "userType": "EMP", 
          "firstName": "Jim", 
          "lastName": "Smith", 
          "createdDate": "2018-01-17T15:41:26", 
          "updatedDate": "2018-02-15T16:16:08", 
          "pwdExpireDate": "2018-11-13T15:46:30", 
              "pwdWarnDate": "2018-06-16T15:46:30", 
          "provisionedDate": "2018-01-17T15:46:30", 
          "pwdExpired": false, 
          "pwdCantChange": false, 
          "pwdWarned": false, 
          "loginAttemptsCtr": "0", 
          "changePwdAtNextLogin": true, 
          "lastAction": "Updated", 
          "disabled": false, 
          "id": "205" 
      }] 
      }
		
To create a user using this JSON data: 
		
curl -u jsmith:mypassword1 -H "Content-Type: application/json" -H "Version:2" -X POST -d "@user_example.json" https://localhost/cloudapi/restapi/user/add-list
		

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