Chilkat Online Tools

SQL Server / Orchestrator / Robot Service - Get Robot Mappings

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

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

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'licenseKey', '86753095683'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'machineName', 'TESTLAPTOP'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-UIPATH-OrganizationUnitId', '{{folderId}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-UIPATH-TenantName', '{{tenantName}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://domain.com/api/RobotsService/GetRobotMappings', @queryParams
    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 @queryParams
        RETURN
      END

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

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

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

    EXEC sp_OAMethod @jarrResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jarrResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jarrResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jarrResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- [
    --   {
    --     "robotKey": "1234567-abcd-890p-a67b-6d5b987dj",
    --     "user": "dean",
    --     "machineName": "TESTLAPTOP",
    --     "machineId": 20000,
    --     "robotName": "joe",
    --     "robotType": 3,
    --     "hasLicense": false,
    --     "tenantId": 1234,
    --     "organizationUnitId": 5678,
    --     "executionSettings": null,
    --     "id": 33445
    --   }
    -- ]

    -- Sample code for parsing the JSON response...
    -- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    DECLARE @json int

    DECLARE @robotKey nvarchar(4000)

    DECLARE @user nvarchar(4000)

    DECLARE @machineName nvarchar(4000)

    DECLARE @machineId int

    DECLARE @robotName nvarchar(4000)

    DECLARE @robotType int

    DECLARE @hasLicense int

    DECLARE @tenantId int

    DECLARE @organizationUnitId int

    DECLARE @executionSettings nvarchar(4000)

    DECLARE @id int

    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAGetProperty @jarrResp, 'Size', @count_i OUT
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OAMethod @jarrResp, 'ObjectAt', @json OUT, @i
        EXEC sp_OAMethod @json, 'StringOf', @robotKey OUT, 'robotKey'
        EXEC sp_OAMethod @json, 'StringOf', @user OUT, 'user'
        EXEC sp_OAMethod @json, 'StringOf', @machineName OUT, 'machineName'
        EXEC sp_OAMethod @json, 'IntOf', @machineId OUT, 'machineId'
        EXEC sp_OAMethod @json, 'StringOf', @robotName OUT, 'robotName'
        EXEC sp_OAMethod @json, 'IntOf', @robotType OUT, 'robotType'
        EXEC sp_OAMethod @json, 'BoolOf', @hasLicense OUT, 'hasLicense'
        EXEC sp_OAMethod @json, 'IntOf', @tenantId OUT, 'tenantId'
        EXEC sp_OAMethod @json, 'IntOf', @organizationUnitId OUT, 'organizationUnitId'
        EXEC sp_OAMethod @json, 'StringOf', @executionSettings OUT, 'executionSettings'
        EXEC sp_OAMethod @json, 'IntOf', @id OUT, 'id'
        EXEC @hr = sp_OADestroy @json

        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jarrResp


END
GO

Curl Command

curl -G -d "licenseKey=86753095683"
	-d "machineName=TESTLAPTOP"
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-H "X-UIPATH-TenantName: {{tenantName}}"
	-H "X-UIPATH-OrganizationUnitId: {{folderId}}"
https://domain.com/api/RobotsService/GetRobotMappings

Postman Collection Item JSON

{
  "name": "Robot Service - Get Robot Mappings",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json",
        "type": "text"
      },
      {
        "key": "X-UIPATH-TenantName",
        "value": "{{tenantName}}",
        "type": "text"
      },
      {
        "key": "X-UIPATH-OrganizationUnitId",
        "value": "{{folderId}}",
        "type": "text"
      }
    ],
    "url": {
      "raw": "{{url}}/api/RobotsService/GetRobotMappings?licenseKey=86753095683&machineName=TESTLAPTOP",
      "host": [
        "{{url}}"
      ],
      "path": [
        "api",
        "RobotsService",
        "GetRobotMappings"
      ],
      "query": [
        {
          "key": "licenseKey",
          "value": "86753095683"
        },
        {
          "key": "machineName",
          "value": "TESTLAPTOP"
        }
      ]
    }
  },
  "response": [
    {
      "name": "Robot Service - Get Robot Service Mappings",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{url}}/api/RobotsService/GetRobotMappings?licenseKey=86753095683&machineName=TESTLAPTOP",
          "host": [
            "{{url}}"
          ],
          "path": [
            "api",
            "RobotsService",
            "GetRobotMappings"
          ],
          "query": [
            {
              "key": "licenseKey",
              "value": "86753095683"
            },
            {
              "key": "machineName",
              "value": "TESTLAPTOP"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Mon, 28 Jan 2019 23:05:37 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json; charset=utf-8"
        },
        {
          "key": "Content-Length",
          "value": "122"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Cache-Control",
          "value": "no-store, must-revalidate, no-cache, max-age=0"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Set-Cookie",
          "value": "; SameSite=lax"
        },
        {
          "key": "api-supported-versions",
          "value": "7.0"
        },
        {
          "key": "Request-Context",
          "value": "appId=cid-v1:d00ce63d-0891-41e4-a17c-25b2c5382e49"
        },
        {
          "key": "Access-Control-Expose-Headers",
          "value": "Request-Context"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-Frame-Options",
          "value": "DENY"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536000; includeSubDomains"
        },
        {
          "key": "Expect-CT",
          "value": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
        },
        {
          "key": "Server",
          "value": "cloudflare"
        },
        {
          "key": "CF-RAY",
          "value": "4a071ad5fc4a247a-IAD"
        }
      ],
      "cookie": [
      ],
      "body": "[\n    {\n        \"robotKey\": \"1234567-abcd-890p-a67b-6d5b987dj\",\n        \"user\": \"dean\",\n        \"machineName\": \"TESTLAPTOP\",\n        \"machineId\": 20000,\n        \"robotName\": \"joe\",\n        \"robotType\": 3,\n        \"hasLicense\": false,\n        \"tenantId\": 1234,\n        \"organizationUnitId\": 5678,\n        \"executionSettings\": null,\n        \"id\": 33445\n    }\n]"
    }
  ]
}