How to get authentication tokens from the Orchestrator Cloud version using HTTP Request Activity?
Summary:
This article provides a detailed set of steps to authenticate in UiPath Cloud Orchestrator and obtain a token using the HTTP Request activity in UiPath Studio. This process is essential for performing authorized operations on the Orchestrator platform through automation using different permissions than the ones the Robot / User account running the automation. Notably, this article will showcase using the API access information from Automation Cloud.
Pre-requisites:
- UiPath Studio installed and licensed. In this article, UiPath Studio 2023.4.6 was used
- Create a new project in UiPath Studio. In this article, a Windows-based was used
- Add the WebAPI Activities package (UiPath.WebAPI.Activities) to the UiPath Studio project. In this article, version 1.18.0 was used
- Administrator Access to UiPath Cloud Account for authentication settings.
To obtain the token follow the procedure:
- UiPath Cloud - Getting the API access information from Automation Cloud
- Navigate to the Orchestrator Cloud "Admin" panel and select the preferred Tenant
- Click on "Services" to display the services list active on the tenant
- Click the three vertical dots icon under the Orchestrator service card and click the "API Access" option to display the API information
- This information needs to be added to the HTTP Request activity later in this article
- See the attached images for reference
- UiPath Studio - Add the HTTP Request activity and configure
- In the properties panel configure the values as follows:
- Enable SSL certificate verification: True
- Timeout (milliseconds): 120000
- Accept Format: JSON
- Request Method: POST
- Request URL (end point): "https://account.uipath.com/oauth/token"
- Body Format: application/x-www-form-urlencoded
- In the Parameters property add these values:
- "grant_type" In String "refresh_token".
- "client_id" In String "Your_Client_ID" (This string is the Cliend ID value obtained from Cloud Orchestrator API shown in a previous step).
- "refresh_token" In String "Your_Refresh_Token" (This refresh token is the User Key value obtained from Cloud Orchestrator API shown in a previous step).
- In the Headers property add this value:
- "X-UIPATH-TenantName" In string "Your_Tenant_Name" (This tenant name is obtained from Cloud Orchestrator API shown in a previous step).
- Response Content: out_Result (create a variable as Ctrl + k).
- Response Status: out_StatusCode (create a variable as Ctrl + k)
- In the properties panel configure the values as follows:
See the attached image as an example.
- UiPath Studio - Add a Deserialize JSON activity to the process and configure
- In the properties panel configure the values as follows:
- JSON String: Resp_Cont (which is the output of the HTTP Request activity)
- TypeArgument: Newtonsoft.Json.Linq.JObject
- JsonObject (create a variable as Ctrl + k): out_Access_Token
- See the attached image as an example
- In the properties panel configure the values as follows:
- UiPath Studio - Add an Assign activity to the process and configure
- On the left side of the activity, create a new variable AccessTokenString
- On the right side of the activity add the following value:
"Bearer " + Convert.ToString(out_Access_Token.GetValue("access_token"))
- See the attached image as an example.
- UiPath Studio - Add a Log Message activity to the process and configure
- Execute the process and check the output panel to print the AccessTokenString variable and confirm if it contains the desired token
- See the attached image as an example of the expected result