Back to Collection Items
#import <CkoHttp.h>
#import <CkoJsonArray.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <CkoHttpResponse.h>
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoHttp *http = [[CkoHttp alloc] init];
BOOL 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.
// [
// {
// "operation": "replace",
// "field": "/telephoneNumber",
// "value": "{{$randomPhoneNumber}}"
// }
// ]
CkoJsonArray *jarr = [[CkoJsonArray alloc] init];
[jarr AddObjectAt: [NSNumber numberWithInt: -1]];
CkoJsonObject *jsonObj_1 = [jarr ObjectAt: [NSNumber numberWithInt: ([jarr.Size intValue] - 1)]];
[jsonObj_1 UpdateString: @"operation" value: @"replace"];
[jsonObj_1 UpdateString: @"field" value: @"/telephoneNumber"];
[jsonObj_1 UpdateString: @"value" value: @"{{$randomPhoneNumber}}"];
[http SetRequestHeader: @"X-OpenIDM-Username" value: @"{{adminUsername}}"];
[http SetRequestHeader: @"Accept-API-Version" value: @"resource=1.0"];
[http SetRequestHeader: @"X-OpenIDM-Password" value: @"{{adminPassword}}"];
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = @"<access_token>";
CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[jarr EmitSb: sbRequestBody];
CkoHttpResponse *resp = [http PTextSb: @"POST" url: @"{{managedUsername}}" textData: sbRequestBody charset: @"utf-8" contentType: @"application/json" md5: NO gzip: NO];
if (http.LastMethodSuccess == NO) {
NSLog(@"%@",http.LastErrorText);
return;
}
NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "Accept-API-Version: resource=1.0"
-H "X-OpenIDM-Username: {{adminUsername}}"
-H "X-OpenIDM-Password: {{adminPassword}}"
-d '[
{
"operation": "replace",
"field": "/telephoneNumber",
"value": "{{$randomPhoneNumber}}"
}
]'
https://<tenant-name>.forgeblocks.com/openidm/managed/alpha_user?_action=patch&_queryFilter=userName eq "{{managedUsername}}"
Postman Collection Item JSON
{
"name": "Step 3: Update a 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);",
"}"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"description": "(Required) ",
"key": "Accept-API-Version",
"value": "resource=1.0",
"disabled": true
},
{
"key": "X-OpenIDM-Username",
"type": "text",
"value": "{{adminUsername}}"
},
{
"key": "X-OpenIDM-Password",
"type": "text",
"value": "{{adminPassword}}"
}
],
"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?_action=patch&_queryFilter=userName eq \"{{managedUsername}}\"",
"host": [
"{{platformUrl}}"
],
"path": [
"openidm",
"managed",
"alpha_user"
],
"query": [
{
"key": "_action",
"value": "patch"
},
{
"key": "_queryFilter",
"value": "userName eq \"{{managedUsername}}\""
},
{
"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
}
]
},
"description": "Update the details, in this case; the telephone number, of a managed identity."
},
"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": ""
}
]
}