Chilkat Online Tools

Node.js / ForgeRock Identity Cloud Collection / Step 7: Create a Demo "Alpha User" Managed Identity

Back to Collection Items

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node21-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node21-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node21-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node21-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node21-linux64');
    }
} else if (os.platform() == 'darwin') {
    if (os.arch() == 'arm64') {
        var chilkat = require('@chilkat/ck-node21-mac-m1');
    } else {
        var chilkat = require('@chilkat/ck-node21-macosx');
    }
}


function chilkatExample() {

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    var http = new chilkat.Http();
    var success;

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "userName": "{{postmanDemoUsername}}",
    //   "sn": "Demo-User",
    //   "givenName": "Postman",
    //   "mail": "{{postmanDemoEmail}}",
    //   "telephoneNumber": "{{$randomPhoneNumber}}",
    //   "password": "{{postmanDemoPassword}}"
    // }

    var json = new chilkat.JsonObject();
    json.UpdateString("userName","{{postmanDemoUsername}}");
    json.UpdateString("sn","Demo-User");
    json.UpdateString("givenName","Postman");
    json.UpdateString("mail","{{postmanDemoEmail}}");
    json.UpdateString("telephoneNumber","{{$randomPhoneNumber}}");
    json.UpdateString("password","{{postmanDemoPassword}}");

    // Adds the "Authorization: Bearer <access_token>" header.
    http.AuthToken = "<access_token>";

    // resp: HttpResponse
    var resp = http.PostJson3("https://<tenant-name>.forgeblocks.com/openidm/managed/alpha_user?_action=create","application/json",json);
    if (http.LastMethodSuccess == false) {
        console.log(http.LastErrorText);
        return;
    }

    console.log(resp.StatusCode);
    console.log(resp.BodyStr);


}

chilkatExample();

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
  "userName": "{{postmanDemoUsername}}",
  "sn": "Demo-User",
  "givenName": "Postman",
  "mail": "{{postmanDemoEmail}}",
  "telephoneNumber": "{{$randomPhoneNumber}}",
  "password": "{{postmanDemoPassword}}"
}'
https://<tenant-name>.forgeblocks.com/openidm/managed/alpha_user?_action=create

Postman Collection Item JSON

{
  "name": "Step 7: Create a Demo \"Alpha User\" Managed Identity",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    },
    {
      "listen": "test",
      "script": {
        "exec": [
          "const jsonData = JSON.parse(responseBody);",
          "if(jsonData._id && jsonData._id != \"\"){",
          "    pm.globals.set(\"managedUserId\", jsonData._id);",
          "}",
          "if(jsonData.userName && jsonData.userName != \"\"){",
          "    pm.globals.set(\"managedUsername\", jsonData.userName);",
          "}"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{adminAccessToken}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"userName\": \"{{postmanDemoUsername}}\",\n  \"sn\": \"Demo-User\",\n  \"givenName\": \"Postman\",\n  \"mail\": \"{{postmanDemoEmail}}\",\n  \"telephoneNumber\": \"{{$randomPhoneNumber}}\",\n  \"password\": \"{{postmanDemoPassword}}\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{platformUrl}}/openidm/managed/alpha_user?_action=create",
      "host": [
        "{{platformUrl}}"
      ],
      "path": [
        "openidm",
        "managed",
        "alpha_user"
      ],
      "query": [
        {
          "key": "_action",
          "value": "create"
        }
      ]
    },
    "description": "Create a demonstration `alpha_user` in the Alpha realm. A number of requests in the Postman Collection require this user to be present, for example the *Intelligent Access* section."
  },
  "response": [
    {
      "name": "Success",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "(Required) ",
            "key": "Accept-API-Version",
            "value": "<string>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/openidm/managed/user#1.0_query_filter?_fields=&_prettyPrint=true&_queryFilter=<string>&_pageSize=<integer>&_totalPagedResultsPolicy=<string>&_sortKeys=<string>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "openidm",
            "managed",
            "user"
          ],
          "hash": "1.0_query_filter?_fields=&_prettyPrint=true&_queryFilter=<string>&_pageSize=<integer>&_totalPagedResultsPolicy=<string>&_sortKeys=<string>"
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "*/*"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}