Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- 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}}"
-- }
-- ]
DECLARE @jarr int
-- Use "Chilkat_9_5_0.JsonArray" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonArray', @jarr OUT
EXEC sp_OAMethod @jarr, 'AddObjectAt', @success OUT, -1
DECLARE @jsonObj_1 int
EXEC sp_OAGetProperty @jarr, 'Size', @iTmp0 OUT
EXEC sp_OAMethod @jarr, 'ObjectAt', @jsonObj_1 OUT, @iTmp0 - 1
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'operation', 'replace'
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'field', '/telephoneNumber'
EXEC sp_OAMethod @jsonObj_1, 'UpdateString', @success OUT, 'value', '{{$randomPhoneNumber}}'
EXEC @hr = sp_OADestroy @jsonObj_1
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-OpenIDM-Username', '{{adminUsername}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept-API-Version', 'resource=1.0'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-OpenIDM-Password', '{{adminPassword}}'
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @jarr, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'POST', '{{managedUsername}}', @sbRequestBody, 'utf-8', 'application/json', 0, 0
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jarr
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @jarr
EXEC @hr = sp_OADestroy @sbRequestBody
END
GO
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": ""
}
]
}