How To Make Orchestrator API Requests Using HTTP Request or Orchestrator HTTP Request Activities in Studio?

How To Make Orchestrator API Requests Using HTTP Request or Orchestrator HTTP Request Activities in Studio?

Note: In the below example, usage of the "/odata/ProcessSchedules" REST API endpoint is explained. Readapt the steps based on current needs. The steps were tested in Studio 2023.4.5 with C# language support and Windows Compatibility.

In order to make Orchestrator API Requests using HTTP Request activities, two options are present:

  1. Orchestrator HTTP Request Activity
  2. HTTP Request Activity

1. Using Orchestrator HTTP Request Activity

  • To use this approach, the Robot should be connected to Orchestrator and it does not require to authenticate the Orchestrator using Authenticate API.
  • This activity uses the UiPath.System.Activities package.
    • Pass the relative endpoint in the "Relative Endpoint" like "/odata/ProcessSchedules"

Refer to the Orchestrator HTTP Request .

An example for the Orchestrator HTTP Request Activity

  1. Find the Orchestrator HTTP Request activity in the Activities panel

1.png

  1. Make sure that Robot is connected to Orchestrator in Studio

2.png

  1. The activity Properties panel should look like this

Method: GET

RelativeEndpoint: "/odata/ProcessSchedules"

Orchestrator Folder Path (specify the full folder path in Orchestrator or choose the folder by using the Arrow): "Shared/UnattendedFolder"

3.png

image.png

  1. Create a variable in JSON Response out_JSONResponse (it will have a String type)

4.png

  1. Use the Deserialize JSON activity. For this, add the UiPath.WebAPI.Activities package in your process.
6.png

5.png

  1. In JSON String provide the already created variable out_JSONResponse, and in JsonObject create a new variable out_JsonObject (TypeArgument: Newtonsoft.Json.Linq.JObject)

7.png

  1. In order to retrieve the needed data, use the For Each activity:
ForEach: json_item

In:

out_JsonObject.GetValue("value")

Message:

"Id: "+ Convert.ToString(json_item.GetValue("Id")) + "\n" + "Name: "+Convert.ToString(json_item.GetValue("Name")) + "\n" + "StartProcessCronDetails: " +Convert.ToString(json_item.GetValue("StartProcessCronDetails"))

8.png

Results:

9.png

2. Using HTTP Request Activity

Robot connectivity with Orchestrator is not required and it is required to authenticate the Orchestrator by making a HTTP POST request to the below API endpoint:

  • [Orchestrator Url]/api/Account/Authenticate (This will work only in On-Premise Orchestrator for all tenants, but is designed more for the Host tenants where you cannot create external applications.)
    • Its response will return a token, which is stored in the "result" key of the JSON response
    • The above parameters need to be passed in the header, to make HTTP Post Request to Start Jobs API.

An example for the Orchestrator HTTP Request Activity:

  1. Find the HTTP Request activity in the Activities panel after you add the UiPath.WebAPI.Activities package in your process.

10.png

  1. In the Properties panel you should have these values in place:

Timeout (milliseconds): 10000

Endpoint: "https://ORCHESTRATOR_URL/api/Account/Authenticate"

Method: POST

Body:

@"{
" + "\n" +
@"""tenancyName"":""TENANT_NAME"",
" + "\n" +
@"""usernameOrEmailAddress"":""USERNAME"",
" + "\n" +
@"""password"":""PASSWORD""
" + "\n" +
@"}";

BodyFormat: application/json

Response content (create a new variable): out_ResponseContent

11.png

  1. Use the Deserialize JSON activity

12.png

In JSON String use out_ResponseContent variable

In JsonObject create a new variable out_AccessToken (it will have Type: Newtonsoft.Json.Linq.JObject)

13.png

  1. Use the Assign activity to transform the Access token value to the expected String value in the Authorization header request.

Create a new variable AccessTokenString that has this value

"Bearer " + Convert.ToString(out_AccessToken.GetValue("result"))

14.png

  1. Add a small Delay to make sure the robot prepared the AccessTokenString

15.png

  1. Use a new HTTP Request activity that has these values configured:

AcceptFormat: ANY

Endpoint: "https://ORCHESTRATOR_URL/odata/ProcessSchedules"

Method: GET

BodyFormat: application/json

In Options -> Headers add two values:

  • Authorization in String AccessTokenString
  • X-UIPATH-FolderPath In String "PlainText FolderPath value" (this is the folder path where the processes are located). More details can find on Building API Requests

16.png


In Output -> Result create a new variable out_ReponseSchedules_ResponseContent

17.png



7. Use the Deserialize JSON activity

JSON String: out_ReponseSchedules_ResponseContent

JsonObject (create a new variable): GetResultsFromDeserialize


18.png

  1. In For Each activity, extract the needed data
  • TypeArgument: Newtonsoft.Json.Linq.JObject
  • Values:
    GetResultsFromDeserialize.GetValue("value")

19.png

  1. Log Message activity:

LogLevel: LogLevel.Info

Message:

"Id: "+ Convert.ToString(json_item.GetValue("Id")) + "\n" + "Name: "+Convert.ToString(json_item.GetValue("Name")) + "\n" + "StartProcessCronDetails: " +Convert.ToString(json_item.GetValue("StartProcessCronDetails"))

Results:

20.png


====


In case you have an external application in your On-Premise or UiPath Cloud Orchestrator, the application Bearer token can be retrieved using the below approach.


Notes:

For On-Premise Orchestrator the URL will be "https://ORCHESTRATOR_URL/identity/connect/token"

ForUiPath Cloud Orchestrator the URL will be "https://cloud.uipath.com/identity_/connect/token"



1. Use an HTTP Request activity that has these values configured:

AcceptFormat: ANY

Endpoint: "https://ORCHESTRATOR_URL/identity/connect/token"

Method: POST

BodyFormat: application/x-www-form-urlencoded

Response content: create a new variable out_Bearer_access_token

In Options -> Parameters add these values:

grant_type in String "client_credentials"
client_id in String "YOUR_CLIENT_ID"
client_secret in String "YOUR_CLIENT_SECRET"
scope in String "YOUR_APPLICATION_SCOPE(S)"

Example:

22.png


23.png

2. Use theDeserialize JSON activity

JSON String: out_Bearer_access_token

JsonObject (create a new variable): out_Access_Token


24.png

3. Use the Assign activity to transform the Access token value to the expected String value in the Authorization header request.

Create a new variable AccessTokenString that has this value

"Bearer " + Convert.ToString(out_Access_Token.GetValue("access_token"))



25.png

Results:

26.png


====

In the case when it is needed to check the @odata.count value of the JSON response, check by adding an extra Log Message activity in the workflow with this Message:

"@odata.count: " + Convert.ToString(out_JsonObject.GetValue("@odata.count"))



Results:

21.png

1 Like

Can you fix the screenshots on this? Most don’t seem to be available any longer. Thank you!

Yes, I will fix them soon.

@L_H please check https://uipath.my.salesforce-sites.com/CaseView/articles/Knowledge/How-To-Make-Orchestrator-API-Requests-Using-HTTP-Request-Activities-or-Orchestrator-HTTP-Request?lang=en_US

Thank you! I appreciate the help

1 Like

Trying desperatly to follow your knowledge base instructions but stuck on the below

plus it says that it does not support post?

You didn’t follow my article. For Cloud instance, you need to use client_credentials to obtain to the token, and also the URL is incorrect.

For UiPath Cloud Orchestrator the URL will be https://cloud.uipath.com/identity_/connect/token

Next time, read the full article.

1 Like