How To Add A Queue Item from Json in StudioX Using HTTP Request Activities?

How to add a Queue item from Json in StudioX using HTTP Request activities?

Prerequisite:
Create an External application on Orchestrator with the required scopes and obtain the Client ID and Client Secret.

Note: In this tutorial, an example of getting the client_credentials access_token and using it afterward in the request of adding a Queue item using the /odata/Queues/UiPathODataSvc.AddQueueItem endpoint is presented. This example can be readapted for any RestApi request endpoints for the StudioX profile.


For StudioX follow the below approach:

  1. From Manage Packages find and install the UiPath.WebAPI.Activities[1.21.0]

image.png

  1. Add HTTP Request activity from the Activities panel

2.png

  1. Configure the Properties panel for the HTTP Request activity as below:

AcceptFormat: ANY

Endpoint: https://cloud.uipath.com/identity_/connect/token

Method: POST

Body: leave empty

BodyFormat: application/x-www-form-urlencoded

Cookies: leave empty

Headers: leave empty

Result: create a variable for example named Results

Parameters:

Example:

grant_type: "client_credentials"

client_id: "Your Client Id from External Application"

scope: "OR.Folders OR.Robots OR.Queues"

client_secret: "Your Client Secret from External Application"

image.png

image.png

  1. If adding a Write Line activity and selecting the Results variable, in the end, run the process, the needed results will be obtained exactly as in the Postman Tool:

5.png

image.png

  1. To get the needed access token and reuse it in another activity, follow the next steps:
  • Use a Write Text File activity as below:

Text: Split(Split(Results, ",")(0).ToString, ":")(1).Replace("""", "")

Write to filename: TokenFromCloud.txt

image.png

  1. Use a Read Text File activity as below:

Filename: TokenFromCloud.txt

8.png

In the Properties panel, save it to Output_to_from_Read_Text_File1

image.png

  1. For testing purposes, use a Write Line activity and select the saved variable

Text: Output_to_from_Read_Text_File1

Results:

image.png

  1. To add a queue item, add the JSON data in a.TXT file in the project and use a Read Text File activity:

JSON data to add a queue item:

{

"itemData": {

"Priority": "Normal",

"DeferDate": "2022-03-21T13:42:27.654Z",

"DueDate": "2022-03-25T13:42:27.654Z",

"Name": "TestQueue",

"Reference": "TestQueue",

"SpecificContent": {

"Email": "xxxxxxx@uipath.com",

"Name": "Sample Test"

}

}

}

image.png

In the Read Text File in the Output to parameter create a new variable named AddQueueItemValue

image.png

  1. For testing purposes, add a Write Line activity to display the content of the variable AddQueueItemValue

image.png

Results:

image.png

  1. Add a new HTTP Request activity and configure it as below:

AcceptFormat: ANY

Endpoint: "https://cloud.uipath.com/ACCOUNT_NAME/TENANT_NAME/odata/Queues/UiPathODataSvc.AddQueueItem"

Method: POST

Body: AddQueueItemValue

BodyFormat: application/json

Cookies: leave empty

Headers:

X-UIPATH-OrganizationUnitId: "FOLDER_ID"

Content-Type: "application/json"

Authorization: "Bearer " + Output_to_from_Read_Text_File1

image.png

Parameters: leave empty

Result: Create a variable for example named ResultOfAddedQueueItem

image.png

  1. For testing purposes, add a Write Line activity to display the content of the variable AddQueueItemValue

Results:

image.png

1 Like