Chilkat Online Tools

Objective-C / Orchestrator API Documentation / Get Folder by Name

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>
#import <CkoStringBuilder.h>
#import <NSString.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

CkoJsonObject *queryParams = [[CkoJsonObject alloc] init];
[queryParams UpdateString: @"$Filter" value: @"DisplayName eq 'UnattendedProcesses'"];

[http SetRequestHeader: @"Content-Type" value: @"application/json"];
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = @"<access_token>";
[http SetRequestHeader: @"X-UIPATH-TenantName" value: @"{{tenantName}}"];

CkoHttpResponse *resp = [http QuickRequestParams: @"GET" url: @"https://domain.com/odata/Folders" json: queryParams];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
[resp GetBodySb: sbResponseBody];

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;

NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);

int respStatusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",resp.Header);
    NSLog(@"%@",@"Failed.");

    return;
}

// 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

NSString *Key = 0;
NSString *DisplayName = 0;
NSString *FullyQualifiedName = 0;
NSString *FullyQualifiedNameOrderable = 0;
NSString *Description = 0;
NSString *ProvisionType = 0;
NSString *PermissionModel = 0;
NSString *ParentId = 0;
NSString *ParentKey = 0;
BOOL IsActive;
NSString *FeedType = 0;
int Id;

NSString *odata_context = [jResp StringOf: @"\"@odata.context\""];
int odata_count = [[jResp IntOf: @"\"@odata.count\""] intValue];
int i = 0;
int count_i = [[jResp SizeOfArray: @"value"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    Key = [jResp StringOf: @"value[i].Key"];
    DisplayName = [jResp StringOf: @"value[i].DisplayName"];
    FullyQualifiedName = [jResp StringOf: @"value[i].FullyQualifiedName"];
    FullyQualifiedNameOrderable = [jResp StringOf: @"value[i].FullyQualifiedNameOrderable"];
    Description = [jResp StringOf: @"value[i].Description"];
    ProvisionType = [jResp StringOf: @"value[i].ProvisionType"];
    PermissionModel = [jResp StringOf: @"value[i].PermissionModel"];
    ParentId = [jResp StringOf: @"value[i].ParentId"];
    ParentKey = [jResp StringOf: @"value[i].ParentKey"];
    IsActive = [jResp BoolOf: @"value[i].IsActive"];
    FeedType = [jResp StringOf: @"value[i].FeedType"];
    Id = [[jResp IntOf: @"value[i].Id"] intValue];
    i = i + 1;
}

Curl Command

curl -G -d "$Filter=DisplayName%20eq%20%27UnattendedProcesses%27"
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-H "X-UIPATH-TenantName: {{tenantName}}"
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"
      },
      {
        "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'"
        }
      ]
    },
    "description": "When executing _GET Folders_ you will receive a list of folders including their IDs. You will need a specific folder ID for the follwwing steps in order to find the right processes to be executed.\n\nThe folder ID will be handed over as _X-UIPATH-OrganizationUnitId_."
  },
  "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 12:54:30 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": "e999f7d3-ed34-4cab-9484-b5b6706d6bb9"
        },
        {
          "key": "OData-Version",
          "value": "4.0"
        },
        {
          "key": "api-supported-versions",
          "value": "12.0"
        },
        {
          "key": "CF-Cache-Status",
          "value": "DYNAMIC"
        },
        {
          "key": "cf-request-id",
          "value": "0929f299c20000cba025357000000001"
        },
        {
          "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": "6389ba093d4ccba0-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}"
    }
  ]
}