Chilkat Online Tools

SQL Server / ForgeRock Identity Cloud Collection / Step 1: Create a Managed Identity

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.

    -- {
    --   "userName": "{{managedUsername}}",
    --   "sn": "{{$randomLastName}}",
    --   "givenName": "{{$randomFirstName}}",
    --   "mail": "{{managedUsername}}@postman.example.com",
    --   "telephoneNumber": "{{$randomPhoneNumber}}",
    --   "password": "{{$randomPassword}}"
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'userName', '{{managedUsername}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'sn', '{{$randomLastName}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'givenName', '{{$randomFirstName}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'mail', '{{managedUsername}}@postman.example.com'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'telephoneNumber', '{{$randomPhoneNumber}}'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'password', '{{$randomPassword}}'

    -- 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 @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://<tenant-name>.forgeblocks.com/openidm/managed/alpha_user/:_id', @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 @json
        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 @json
    EXEC @hr = sp_OADestroy @sbRequestBody


END
GO

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": ""
    }
  ]
}