Chilkat Online Tools

PureBasic / ForgeRock Identity Cloud Collection / Step 1: Create a Managed Identity

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

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

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; 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": "{{managedUsername}}",
    ;   "sn": "{{$randomLastName}}",
    ;   "givenName": "{{$randomFirstName}}",
    ;   "mail": "{{managedUsername}}@postman.example.com",
    ;   "telephoneNumber": "{{$randomPhoneNumber}}",
    ;   "password": "{{$randomPassword}}"
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"userName","{{managedUsername}}")
    CkJsonObject::ckUpdateString(json,"sn","{{$randomLastName}}")
    CkJsonObject::ckUpdateString(json,"givenName","{{$randomFirstName}}")
    CkJsonObject::ckUpdateString(json,"mail","{{managedUsername}}@postman.example.com")
    CkJsonObject::ckUpdateString(json,"telephoneNumber","{{$randomPhoneNumber}}")
    CkJsonObject::ckUpdateString(json,"password","{{$randomPassword}}")

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")

    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckEmitSb(json,sbRequestBody)

    resp.i = CkHttp::ckPTextSb(http,"PUT","https://<tenant-name>.forgeblocks.com/openidm/managed/alpha_user/:_id",sbRequestBody,"utf-8","application/json",0,0)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)
    CkStringBuilder::ckDispose(sbRequestBody)


    ProcedureReturn
EndProcedure

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-d '{
  "userName": "{{managedUsername}}",
  "sn": "{{$randomLastName}}",
  "givenName": "{{$randomFirstName}}",
  "mail": "{{managedUsername}}@postman.example.com",
  "telephoneNumber": "{{$randomPhoneNumber}}",
  "password": "{{$randomPassword}}"
}'
https://<tenant-name>.forgeblocks.com/openidm/managed/alpha_user/:_id

Postman Collection Item JSON

{
  "name": "Step 1: Create a Managed Identity",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          "pm.globals.set(\"managedUserId\", pm.globals.replaceIn('{{$guid}}'))",
          "pm.globals.set(\"managedUsername\", pm.globals.replaceIn('{{$randomUserName}}'))"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "PUT",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"userName\": \"{{managedUsername}}\",\n  \"sn\": \"{{$randomLastName}}\",\n  \"givenName\": \"{{$randomFirstName}}\",\n  \"mail\": \"{{managedUsername}}@postman.example.com\",\n  \"telephoneNumber\": \"{{$randomPhoneNumber}}\",\n  \"password\": \"{{$randomPassword}}\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{platformUrl}}/openidm/managed/alpha_user/:_id",
      "host": [
        "{{platformUrl}}"
      ],
      "path": [
        "openidm",
        "managed",
        "alpha_user",
        ":_id"
      ],
      "variable": [
        {
          "key": "_id",
          "value": "{{managedUserId}}"
        }
      ]
    }
  },
  "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": ""
    }
  ]
}