Chilkat Online Tools

unicodeC / ForgeRock Identity Cloud Collection / Step 3: Update a Managed Identity

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonArrayW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonArrayW jarr;
    HCkJsonObjectW jsonObj_1;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

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

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

    // [
    //   {
    //     "operation": "replace",
    //     "field": "/telephoneNumber",
    //     "value": "{{$randomPhoneNumber}}"
    //   }
    // ]

    jarr = CkJsonArrayW_Create();

    CkJsonArrayW_AddObjectAt(jarr,-1);
    jsonObj_1 = CkJsonArrayW_ObjectAt(jarr,CkJsonArrayW_getSize(jarr) - 1);
    CkJsonObjectW_UpdateString(jsonObj_1,L"operation",L"replace");
    CkJsonObjectW_UpdateString(jsonObj_1,L"field",L"/telephoneNumber");
    CkJsonObjectW_UpdateString(jsonObj_1,L"value",L"{{$randomPhoneNumber}}");
    CkJsonObjectW_Dispose(jsonObj_1);

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonArrayW_EmitSb(jarr,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PATCH",L"https://<tenant-name>.forgeblocks.com/openidm/managed/alpha_user/:_id",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonArrayW_Dispose(jarr);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonArrayW_Dispose(jarr);
    CkStringBuilderW_Dispose(sbRequestBody);

    }

Curl Command

curl -X PATCH
	-H "Authorization: Bearer <access_token>"
	-d '[
    {
        "operation": "replace",
        "field": "/telephoneNumber",
        "value": "{{$randomPhoneNumber}}"
    }
]'
https://<tenant-name>.forgeblocks.com/openidm/managed/alpha_user/:_id

Postman Collection Item JSON

{
  "name": "Step 3: Update a Managed Identity",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "PATCH",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "[\n    {\n        \"operation\": \"replace\",\n        \"field\": \"/telephoneNumber\",\n        \"value\": \"{{$randomPhoneNumber}}\"\n    }\n]",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{platformUrl}}/openidm/managed/alpha_user/:_id",
      "host": [
        "{{platformUrl}}"
      ],
      "path": [
        "openidm",
        "managed",
        "alpha_user",
        ":_id"
      ],
      "query": [
        {
          "key": "_fields",
          "value": "",
          "description": "Optional parameter containing a comma separated list of field references specifying which fields of the targeted JSON resource should be returned.",
          "disabled": true
        }
      ],
      "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": ""
    }
  ]
}