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:
- Orchestrator HTTP Request Activity
- 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
- Find the Orchestrator HTTP Request activity in the Activities panel
- Make sure that Robot is connected to Orchestrator in Studio
- 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"
- Create a variable in JSON Response out_JSONResponse (it will have a String type)
- Use the Deserialize JSON activity. For this, add the UiPath.WebAPI.Activities package in your process.
- In JSON String provide the already created variable out_JSONResponse, and in JsonObject create a new variable out_JsonObject (TypeArgument: Newtonsoft.Json.Linq.JObject)
- In order to retrieve the needed data, use the For Each activity:
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"))
Results:
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:
- Find the HTTP Request activity in the Activities panel after you add the UiPath.WebAPI.Activities package in your process.
- 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
- Use the Deserialize JSON activity
In JSON String use out_ResponseContent variable
In JsonObject create a new variable out_AccessToken (it will have Type: Newtonsoft.Json.Linq.JObject)
- 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"))
- Add a small Delay to make sure the robot prepared the AccessTokenString
- 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
In Output -> Result create a new variable out_ReponseSchedules_ResponseContent
JSON String: out_ReponseSchedules_ResponseContent
JsonObject (create a new variable): GetResultsFromDeserialize
- In For Each activity, extract the needed data
- TypeArgument: Newtonsoft.Json.Linq.JObject
- Values:
GetResultsFromDeserialize.GetValue("value")
- 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:
====
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:
2. Use theDeserialize JSON activity
JSON String: out_Bearer_access_token
JsonObject (create a new variable): out_Access_Token
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"))
Results:
====
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: