Using Node.js
Perform the following steps to set up your environment and create a user for Primavera Administration using the API.
Step 1: Obtain Account Information
Contact your account administrator to obtain the account credentials required to manage users using the API. You will need:
- Username and password for Primavera Administration
- The URL of your Primavera Administration instance
Step 2: Install Node.js
The examples within this topic demonstrate how to access the API using Node.js.
When you connect to the API, you must provide an SSL certificate authority (CA) certificate file or bundle to authenticate against the Verisign CA certificate. See also:
To install Node.js on a Windows 64-bit system:
- In your browser, navigate to the Node.js home page and select Downloads.
- Download and run the latest Node.js Windows Installer.
You are now ready to send requests to Primavera Administration using Node.js.
Step 3: Create a User
To create a user using the API, send an HTTP POST request to the /user
endpoint. Your POST request must include additional JSON data that specifies the user name, email address, organization, user type, last name and first name. This example uses a JSON file named user_example.json to specify the properties of the new user. The user_example.json file contains the following JSON data:
{"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, use a Node.js script similar to the following user-request.js:
var https = require('https'); var fs = require('fs'); var postData = fs.readFileSync('user-example.json', 'utf8'); var options = { hostname : "localhost", port : 80, method : 'POST', path : "/cloudapi/restapi/user/add-list", auth : "jsmith:mypassword1", headers:{ "Content-Type" : "application/json", "Version" : "2", "Accept" : "application/json", "Version" : "2" } } var request = https.request(options, function(result){ result.setEncoding('utf8'); result.on('data', function(response){ console.log(response); }); }); request.on('error', function(err){ console.log("Could not process request: ", err); }); request.on('end', function(){ console.log("Finished processing response."); }); request.write(postData); request.end();
Run the following node
command to process your node script and send a request to the server:
node user-request.js
Note: If the user specified with the auth
property 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.