Chilkat Online Tools

PureBasic / Orchestrator API Documentation / Add Queue Item

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

    ; Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    ; The following JSON is sent in the request body.

    ; {
    ;   "itemData": {
    ;     "DeferDate": "2021-03-11T14:19:56.4407392Z",
    ;     "DueDate": "2021-03-11T15:19:56.4407392Z",
    ;     "Priority": "Normal",
    ;     "Name": "UnattendedQueue",
    ;     "SpecificContent": {
    ;       "Name@odata.type": "#String",
    ;       "Name": "Testymonika2000"
    ;     },
    ;     "Reference": "Petstore"
    ;   }
    ; }

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

    CkJsonObject::ckUpdateString(json,"itemData.DeferDate","2021-03-11T14:19:56.4407392Z")
    CkJsonObject::ckUpdateString(json,"itemData.DueDate","2021-03-11T15:19:56.4407392Z")
    CkJsonObject::ckUpdateString(json,"itemData.Priority","Normal")
    CkJsonObject::ckUpdateString(json,"itemData.Name","UnattendedQueue")
    CkJsonObject::ckUpdateString(json,"itemData.SpecificContent." + Chr(34) + "Name@odata.type" + Chr(34),"#String")
    CkJsonObject::ckUpdateString(json,"itemData.SpecificContent.Name","Testymonika2000")
    CkJsonObject::ckUpdateString(json,"itemData.Reference","Petstore")

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

    resp.i = CkHttp::ckPostJson3(http,"https://domain.com/odata/Queues/UiPathODataSvc.AddQueueItem","application/json",json)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        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(json)
        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#QueueItems/$entity",
    ;   "QueueDefinitionId": 28211,
    ;   "OutputData": null,
    ;   "AnalyticsData": null,
    ;   "Status": "New",
    ;   "ReviewStatus": "None",
    ;   "ReviewerUserId": null,
    ;   "Key": "883749b2-70cd-4beb-b0a7-4fd260d26635",
    ;   "Reference": "Petstore",
    ;   "ProcessingExceptionType": null,
    ;   "DueDate": "2021-03-11T15:19:56.4407392Z",
    ;   "RiskSlaDate": null,
    ;   "Priority": "Normal",
    ;   "DeferDate": "2021-03-11T14:19:56.4407392Z",
    ;   "StartProcessing": null,
    ;   "EndProcessing": null,
    ;   "SecondsInPreviousAttempts": 0,
    ;   "AncestorId": null,
    ;   "RetryNumber": 0,
    ;   "SpecificData": "{\"DynamicProperties\":{\"Name\":\"Testymonika2000\"}}",
    ;   "CreationTime": "2021-03-31T12:55:21.7835527Z",
    ;   "Progress": null,
    ;   "RowVersion": "AAAAAAbEaR8=",
    ;   "OrganizationUnitId": 515128,
    ;   "OrganizationUnitFullyQualifiedName": null,
    ;   "Id": 45403309,
    ;   "ProcessingException": null,
    ;   "SpecificContent": {
    ;     "Name": "Testymonika2000"
    ;   },
    ;   "Output": null,
    ;   "Analytics": null
    ; }

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

    odata_context.s = CkJsonObject::ckStringOf(jResp,Chr(34) + "@odata.context" + Chr(34))
    QueueDefinitionId.i = CkJsonObject::ckIntOf(jResp,"QueueDefinitionId")
    OutputData.s = CkJsonObject::ckStringOf(jResp,"OutputData")
    AnalyticsData.s = CkJsonObject::ckStringOf(jResp,"AnalyticsData")
    Status.s = CkJsonObject::ckStringOf(jResp,"Status")
    ReviewStatus.s = CkJsonObject::ckStringOf(jResp,"ReviewStatus")
    ReviewerUserId.s = CkJsonObject::ckStringOf(jResp,"ReviewerUserId")
    Key.s = CkJsonObject::ckStringOf(jResp,"Key")
    Reference.s = CkJsonObject::ckStringOf(jResp,"Reference")
    ProcessingExceptionType.s = CkJsonObject::ckStringOf(jResp,"ProcessingExceptionType")
    DueDate.s = CkJsonObject::ckStringOf(jResp,"DueDate")
    RiskSlaDate.s = CkJsonObject::ckStringOf(jResp,"RiskSlaDate")
    Priority.s = CkJsonObject::ckStringOf(jResp,"Priority")
    DeferDate.s = CkJsonObject::ckStringOf(jResp,"DeferDate")
    StartProcessing.s = CkJsonObject::ckStringOf(jResp,"StartProcessing")
    EndProcessing.s = CkJsonObject::ckStringOf(jResp,"EndProcessing")
    SecondsInPreviousAttempts.i = CkJsonObject::ckIntOf(jResp,"SecondsInPreviousAttempts")
    AncestorId.s = CkJsonObject::ckStringOf(jResp,"AncestorId")
    RetryNumber.i = CkJsonObject::ckIntOf(jResp,"RetryNumber")
    SpecificData.s = CkJsonObject::ckStringOf(jResp,"SpecificData")
    CreationTime.s = CkJsonObject::ckStringOf(jResp,"CreationTime")
    Progress.s = CkJsonObject::ckStringOf(jResp,"Progress")
    RowVersion.s = CkJsonObject::ckStringOf(jResp,"RowVersion")
    OrganizationUnitId.i = CkJsonObject::ckIntOf(jResp,"OrganizationUnitId")
    OrganizationUnitFullyQualifiedName.s = CkJsonObject::ckStringOf(jResp,"OrganizationUnitFullyQualifiedName")
    Id.i = CkJsonObject::ckIntOf(jResp,"Id")
    ProcessingException.s = CkJsonObject::ckStringOf(jResp,"ProcessingException")
    Name.s = CkJsonObject::ckStringOf(jResp,"SpecificContent.Name")
    Output.s = CkJsonObject::ckStringOf(jResp,"Output")
    Analytics.s = CkJsonObject::ckStringOf(jResp,"Analytics")


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


    ProcedureReturn
EndProcedure

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "X-UIPATH-OrganizationUnitId: {{folderId}}"
	-H "Content-Type: application/json"
	-d '{
    "itemData": {
        "DeferDate": "2021-03-11T14:19:56.4407392Z",
        "DueDate": "2021-03-11T15:19:56.4407392Z",
        "Priority": "Normal",
        "Name": "UnattendedQueue",
        "SpecificContent": {
            "Name@odata.type": "#String",
            "Name": "Testymonika2000"
        },
        "Reference": "Petstore"
    }
}'
https://domain.com/odata/Queues/UiPathODataSvc.AddQueueItem

Postman Collection Item JSON

{
  "name": "Add Queue Item",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "//test status code\r",
          "pm.test(\"Status code is 201\", function () {\r",
          "    pm.response.to.have.status(201);\r",
          "});\r",
          "\r",
          "//set JobId key\r",
          "var myResponse = pm.response.json();\r",
          "pm.collectionVariables.set(\"queueItemId\", myResponse.Id);\r",
          "console.log(pm.collectionVariables.get(\"queueItemId\"));"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "description": "Folder/OrganizationUnit Id",
        "key": "X-UIPATH-OrganizationUnitId",
        "value": "{{folderId}}"
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"itemData\": {\n        \"DeferDate\": \"2021-03-11T14:19:56.4407392Z\",\n        \"DueDate\": \"2021-03-11T15:19:56.4407392Z\",\n        \"Priority\": \"Normal\",\n        \"Name\": \"UnattendedQueue\",\n        \"SpecificContent\": {\n            \"Name@odata.type\": \"#String\",\n            \"Name\": \"Testymonika2000\"\n        },\n        \"Reference\": \"Petstore\"\n    }\n}"
    },
    "url": {
      "raw": "{{url}}/odata/Queues/UiPathODataSvc.AddQueueItem",
      "host": [
        "{{url}}"
      ],
      "path": [
        "odata",
        "Queues",
        "UiPathODataSvc.AddQueueItem"
      ],
      "query": [
        {
          "key": "$expand",
          "value": "",
          "description": "Indicates the related entities to be represented inline. The maximum depth is 2.",
          "disabled": true
        },
        {
          "key": "$select",
          "value": "",
          "description": "Limits the properties returned in the result.",
          "disabled": true
        }
      ]
    },
    "description": "OAuth required scopes: OR.Queues or OR.Queues.Write.\r\n\r\nRequired permissions: Queues.View and Transactions.Create."
  },
  "response": [
    {
      "name": "Add Queue Item",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Folder/OrganizationUnit Id",
            "key": "X-UIPATH-OrganizationUnitId",
            "value": "{{folderId}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"itemData\": {\n        \"DeferDate\": \"2021-03-11T14:19:56.4407392Z\",\n        \"DueDate\": \"2021-03-11T15:19:56.4407392Z\",\n        \"Priority\": \"Normal\",\n        \"Name\": \"UnattendedQueue\",\n        \"SpecificContent\": {\n            \"Name@odata.type\": \"#String\",\n            \"Name\": \"Testymonika2000\"\n        },\n        \"Reference\": \"Petstore\"\n    }\n}"
        },
        "url": {
          "raw": "{{url}}/odata/Queues/UiPathODataSvc.AddQueueItem",
          "host": [
            "{{url}}"
          ],
          "path": [
            "odata",
            "Queues",
            "UiPathODataSvc.AddQueueItem"
          ],
          "query": [
            {
              "key": "$expand",
              "value": "",
              "description": "Indicates the related entities to be represented inline. The maximum depth is 2.",
              "disabled": true
            },
            {
              "key": "$select",
              "value": "",
              "description": "Limits the properties returned in the result.",
              "disabled": true
            }
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Wed, 31 Mar 2021 12:55:21 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": "Location",
          "value": "https://cloud.uipath.com/robertorg/modernDepartment/orchestrator_/odata/QueueItems(45403309)"
        },
        {
          "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": "d758dbc2-952a-4cc6-b6d7-0685f3a83b7e"
        },
        {
          "key": "OData-Version",
          "value": "4.0"
        },
        {
          "key": "api-supported-versions",
          "value": "12.0"
        },
        {
          "key": "CF-Cache-Status",
          "value": "DYNAMIC"
        },
        {
          "key": "cf-request-id",
          "value": "0929f3610d0000cba027173000000001"
        },
        {
          "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": "6389bb481bf4cba0-VIE"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"@odata.context\": \"https://cloud.uipath.com/org/tenant/orchestrator_/odata/$metadata#QueueItems/$entity\",\n    \"QueueDefinitionId\": 28211,\n    \"OutputData\": null,\n    \"AnalyticsData\": null,\n    \"Status\": \"New\",\n    \"ReviewStatus\": \"None\",\n    \"ReviewerUserId\": null,\n    \"Key\": \"883749b2-70cd-4beb-b0a7-4fd260d26635\",\n    \"Reference\": \"Petstore\",\n    \"ProcessingExceptionType\": null,\n    \"DueDate\": \"2021-03-11T15:19:56.4407392Z\",\n    \"RiskSlaDate\": null,\n    \"Priority\": \"Normal\",\n    \"DeferDate\": \"2021-03-11T14:19:56.4407392Z\",\n    \"StartProcessing\": null,\n    \"EndProcessing\": null,\n    \"SecondsInPreviousAttempts\": 0,\n    \"AncestorId\": null,\n    \"RetryNumber\": 0,\n    \"SpecificData\": \"{\\\"DynamicProperties\\\":{\\\"Name\\\":\\\"Testymonika2000\\\"}}\",\n    \"CreationTime\": \"2021-03-31T12:55:21.7835527Z\",\n    \"Progress\": null,\n    \"RowVersion\": \"AAAAAAbEaR8=\",\n    \"OrganizationUnitId\": 515128,\n    \"OrganizationUnitFullyQualifiedName\": null,\n    \"Id\": 45403309,\n    \"ProcessingException\": null,\n    \"SpecificContent\": {\n        \"Name\": \"Testymonika2000\"\n    },\n    \"Output\": null,\n    \"Analytics\": null\n}"
    }
  ]
}