Chilkat Online Tools

PureBasic / Orchestrator API Documentation / Get Folder by Name

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    queryParams.i = CkJsonObject::ckCreate()
    If queryParams.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(queryParams,"$Filter","DisplayName eq 'UnattendedProcesses'")

    ; Adds the "Authorization: Bearer <access_token>" header.
    CkHttp::setCkAuthToken(http, "<access_token>")
    CkHttp::ckSetRequestHeader(http,"Content-Type","application/json")

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://domain.com/odata/Folders",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

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

    ; {
    ;   "@odata.context": "https://cloud.uipath.com/org/tenant/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

    Key.s
    DisplayName.s
    FullyQualifiedName.s
    FullyQualifiedNameOrderable.s
    Description.s
    ProvisionType.s
    PermissionModel.s
    ParentId.s
    ParentKey.s
    IsActive.i
    FeedType.s
    Id.i

    odata_context.s = CkJsonObject::ckStringOf(jResp,Chr(34) + "@odata.context" + Chr(34))
    odata_count.i = CkJsonObject::ckIntOf(jResp,Chr(34) + "@odata.count" + Chr(34))
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"value")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        Key = CkJsonObject::ckStringOf(jResp,"value[i].Key")
        DisplayName = CkJsonObject::ckStringOf(jResp,"value[i].DisplayName")
        FullyQualifiedName = CkJsonObject::ckStringOf(jResp,"value[i].FullyQualifiedName")
        FullyQualifiedNameOrderable = CkJsonObject::ckStringOf(jResp,"value[i].FullyQualifiedNameOrderable")
        Description = CkJsonObject::ckStringOf(jResp,"value[i].Description")
        ProvisionType = CkJsonObject::ckStringOf(jResp,"value[i].ProvisionType")
        PermissionModel = CkJsonObject::ckStringOf(jResp,"value[i].PermissionModel")
        ParentId = CkJsonObject::ckStringOf(jResp,"value[i].ParentId")
        ParentKey = CkJsonObject::ckStringOf(jResp,"value[i].ParentKey")
        IsActive = CkJsonObject::ckBoolOf(jResp,"value[i].IsActive")
        FeedType = CkJsonObject::ckStringOf(jResp,"value[i].FeedType")
        Id = CkJsonObject::ckIntOf(jResp,"value[i].Id")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

curl -G -d "$Filter=DisplayName%20eq%20%27UnattendedProcesses%27"
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
https://domain.com/odata/Folders

Postman Collection Item JSON

{
  "name": "Get Folder by Name",
  "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",
          "});\r",
          "\r",
          "//check Id property\r",
          "pm.test('Has ID property', function()\r",
          "{\r",
          " myResponse.value.Id == false;\r",
          "}\r",
          ");\r",
          "//validate schema\r",
          "const schema = {\r",
          "\"type\": \"object\",\r",
          " \"properties\": {\r",
          "        \"value\": { \"Id\" : \"integer\" }\r",
          "    }\r",
          "};\r",
          "pm.test(\"Validate schema\", () => {\r",
          "pm.response.to.have.jsonSchema(schema);\r",
          "});\r",
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "type": "text",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{url}}/odata/Folders?$Filter=DisplayName eq 'UnattendedProcesses'",
      "host": [
        "{{url}}"
      ],
      "path": [
        "odata",
        "Folders"
      ],
      "query": [
        {
          "key": "$Filter",
          "value": "DisplayName eq 'UnattendedProcesses'"
        }
      ]
    },
    "description": "Folder Validation and Type\n--------------------------\nIt is recommended that the connector validate the entered **Fully Qualified Name** of the folder before making subsequent calls.\nThis can be done with the Get Folders API. If there is no folder by that name, then the call will return 0 items, and the error can be flagged to the user. The *Id* of the folder returned in the response should also be stored as it will be needed in some API calls like _StartProcess_ and has to be used as HTTP Header property value for *X-UIPATH-OrganizationUnitId*.\n\nDepending on the type of the folder (Classic or Modern), the configuration of certain API calls like Start Job will change. So, it is necessary to know the type of the folder to enable proper configuration of those API calls. The folder type is indicated by the **ProvisionType** of the folder in the Get Folders API response. **Modern folders** are **Automatic**, whereas **classic folders** are **Manual**."
  },
  "response": [
    {
      "name": "Get Folder by Name",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "type": "text",
            "value": "application/json"
          },
          {
            "key": "X-UIPATH-TenantName",
            "value": "{{tenantName}}",
            "type": "text"
          }
        ],
        "url": {
          "raw": "{{url}}/odata/Folders?$Filter=DisplayName eq 'UnattendedProcesses'",
          "host": [
            "{{url}}"
          ],
          "path": [
            "odata",
            "Folders"
          ],
          "query": [
            {
              "key": "$Filter",
              "value": "DisplayName eq 'UnattendedProcesses'"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Wed, 31 Mar 2021 09:25:02 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": "6e03f63e-0eb6-4b21-8a32-6288e063cba8"
        },
        {
          "key": "OData-Version",
          "value": "4.0"
        },
        {
          "key": "api-supported-versions",
          "value": "12.0"
        },
        {
          "key": "CF-Cache-Status",
          "value": "DYNAMIC"
        },
        {
          "key": "cf-request-id",
          "value": "092932d0e70000cbcc7b837000000001"
        },
        {
          "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": "6388872e3c02cbcc-VIE"
        },
        {
          "key": "Content-Encoding",
          "value": "br"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"@odata.context\": \"https://cloud.uipath.com/org/tenant/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}"
    }
  ]
}