Chilkat Online Tools

SQL Server / Orchestrator API Documentation / GET Folders

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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, '$Filter', 'DisplayName eq ''UnattendedProcesses'''

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://domain.com/orchestrator_/odata/folders', @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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

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

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

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


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, '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 @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

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

    -- {
    --   "@odata.context": "https://cloud.uipath.com/robertorg/modernDepartment/orchestrator_/odata/$metadata#Folders",
    --   "@odata.count": 1,
    --   "value": [
    --     {
    --       "Key": "0d521387-6fb2-4055-a22c-62b7225565b4",
    --       "DisplayName": "UnattendedProcesses",
    --       "FullyQualifiedName": "UnattendedProcesses",
    --       "FullyQualifiedNameOrderable": "UnattendedProcesses",
    --       "Description": null,
    --       "ProvisionType": "Automatic",
    --       "PermissionModel": "FineGrained",
    --       "ParentId": null,
    --       "ParentKey": null,
    --       "IsActive": true,
    --       "FeedType": "Processes",
    --       "Id": 515128
    --     }
    --   ]
    -- }

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

    DECLARE @Key nvarchar(4000)

    DECLARE @DisplayName nvarchar(4000)

    DECLARE @FullyQualifiedName nvarchar(4000)

    DECLARE @FullyQualifiedNameOrderable nvarchar(4000)

    DECLARE @Description nvarchar(4000)

    DECLARE @ProvisionType nvarchar(4000)

    DECLARE @PermissionModel nvarchar(4000)

    DECLARE @ParentId nvarchar(4000)

    DECLARE @ParentKey nvarchar(4000)

    DECLARE @IsActive int

    DECLARE @FeedType nvarchar(4000)

    DECLARE @Id int

    DECLARE @odata_context nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @odata_context OUT, '"@odata.context"'
    DECLARE @odata_count int
    EXEC sp_OAMethod @jResp, 'IntOf', @odata_count OUT, '"@odata.count"'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'value'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @Key OUT, 'value[i].Key'
        EXEC sp_OAMethod @jResp, 'StringOf', @DisplayName OUT, 'value[i].DisplayName'
        EXEC sp_OAMethod @jResp, 'StringOf', @FullyQualifiedName OUT, 'value[i].FullyQualifiedName'
        EXEC sp_OAMethod @jResp, 'StringOf', @FullyQualifiedNameOrderable OUT, 'value[i].FullyQualifiedNameOrderable'
        EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'value[i].Description'
        EXEC sp_OAMethod @jResp, 'StringOf', @ProvisionType OUT, 'value[i].ProvisionType'
        EXEC sp_OAMethod @jResp, 'StringOf', @PermissionModel OUT, 'value[i].PermissionModel'
        EXEC sp_OAMethod @jResp, 'StringOf', @ParentId OUT, 'value[i].ParentId'
        EXEC sp_OAMethod @jResp, 'StringOf', @ParentKey OUT, 'value[i].ParentKey'
        EXEC sp_OAMethod @jResp, 'BoolOf', @IsActive OUT, 'value[i].IsActive'
        EXEC sp_OAMethod @jResp, 'StringOf', @FeedType OUT, 'value[i].FeedType'
        EXEC sp_OAMethod @jResp, 'IntOf', @Id OUT, 'value[i].Id'
        SELECT @i = @i + 1
      END

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


END
GO

Curl Command

curl -G -d "$Filter=DisplayName%20eq%20%27UnattendedProcesses%27"
	-H "Authorization: Bearer <access_token>"
https://domain.com/orchestrator_/odata/folders

Postman Collection Item JSON

{
  "name": "GET Folders",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "//set folder ID\r",
          "var myResponse = pm.response.json();\r",
          "pm.collectionVariables.set(\"folderId\", myResponse.value[0].Id);\r",
          "console.log(pm.collectionVariables.get(\"folderId\"));\r",
          "\r",
          "//test status code\r",
          "pm.test(\"Status code is 200\", function () {\r",
          "    pm.response.to.have.status(200);\r",
          "});"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{url}}/orchestrator_/odata/folders?$Filter=DisplayName eq 'UnattendedProcesses'",
      "host": [
        "{{url}}"
      ],
      "path": [
        "orchestrator_",
        "odata",
        "folders"
      ],
      "query": [
        {
          "key": "$Filter",
          "value": "DisplayName eq 'UnattendedProcesses'"
        }
      ]
    }
  },
  "response": [
    {
      "name": "Test",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{url}}/orchestrator_/odata/folders?$Filter=DisplayName eq 'UnattendedProcesses'",
          "host": [
            "{{url}}"
          ],
          "path": [
            "orchestrator_",
            "odata",
            "folders"
          ],
          "query": [
            {
              "key": "$Filter",
              "value": "DisplayName eq 'UnattendedProcesses'"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 29 Apr 2021 07:07:26 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json; odata.metadata=minimal; odata.streaming=true"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache, no-store, must-revalidate"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Expires",
          "value": "-1"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Request-Context",
          "value": "appId=cid-v1:04884d99-0742-441b-a23c-847133cb0130"
        },
        {
          "key": "X-Robots-Tag",
          "value": "noindex,nofollow"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-Frame-Options",
          "value": "Deny"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536000; includeSubDomains"
        },
        {
          "key": "Content-Security-Policy",
          "value": "default-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: https://*.blob.core.windows.net https://*.amazonaws.com blob:;font-src 'self' data:;connect-src 'self' wss: https://sentry.io https://studio-feedback.azure-api.net https://storage.googleapis.com https://*.service.signalr.net https://*.blob.core.windows.net https://*.amazonaws.com dc.services.visualstudio.com;worker-src 'self' blob:"
        },
        {
          "key": "X-Correlation-ID",
          "value": "b3389aa9-ce79-4516-8a18-88aaa1d750f2"
        },
        {
          "key": "OData-Version",
          "value": "4.0"
        },
        {
          "key": "api-supported-versions",
          "value": "12.0"
        },
        {
          "key": "CF-Cache-Status",
          "value": "DYNAMIC"
        },
        {
          "key": "cf-request-id",
          "value": "09be0d432000000d6ba1821000000001"
        },
        {
          "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": "6476b17e9f840d6b-VIE"
        },
        {
          "key": "Content-Encoding",
          "value": "br"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"@odata.context\": \"https://cloud.uipath.com/robertorg/modernDepartment/orchestrator_/odata/$metadata#Folders\",\n    \"@odata.count\": 1,\n    \"value\": [\n        {\n            \"Key\": \"0d521387-6fb2-4055-a22c-62b7225565b4\",\n            \"DisplayName\": \"UnattendedProcesses\",\n            \"FullyQualifiedName\": \"UnattendedProcesses\",\n            \"FullyQualifiedNameOrderable\": \"UnattendedProcesses\",\n            \"Description\": null,\n            \"ProvisionType\": \"Automatic\",\n            \"PermissionModel\": \"FineGrained\",\n            \"ParentId\": null,\n            \"ParentKey\": null,\n            \"IsActive\": true,\n            \"FeedType\": \"Processes\",\n            \"Id\": 515128\n        }\n    ]\n}"
    }
  ]
}