How to retrieve the Bearer token from the On-Premise Orchestrator using the HTTP Request Activity via a Basic Authentication?
For a VB project use the below details in the workflow
- In the UiPath Studio project add the UiPath.WebAPI.Activities package:
In Workflow add an HTTP Request activity with these details:
Timeout (milliseconds): 30000
AcceptFormat: ANY
RequestMethod: POST
Request URL: "https://ORCHESTRATOR_HOSTNAME/api/Account/Authenticate"
Body:
Body Format: application/json
Response content: Create a new variable (Ctrl + k) named ResponseResults
AcceptFormat: ANY
RequestMethod: POST
Request URL: "https://ORCHESTRATOR_HOSTNAME/api/Account/Authenticate"
Body:
"{""tenancyName"": ""TENANT_NAME"",""usernameOrEmailAddress"": ""USERNAME"",""password"": ""PASSWORD""}"
Body Format: application/json
Response content: Create a new variable (Ctrl + k) named ResponseResults
Example:
- Add a Deserialize JSON activity as below:
- Add an Assign activity as below:
To: Create a new varible (Ctrl + k) named AccessTokenString
Value:
Value:
"Bearer " + Convert.ToString(AccessToken.GetValue("result"))
- The AccessTokenString variable will hold the Bearer access token to continue Orchestrator API requests.
For a C# project use the below details in the workflow
- In the UiPath Studio project add the UiPath.WebAPI.Activities package:
In Workflow add an HTTP Request activity with these details:
Timeout (milliseconds): 30000
AcceptFormat: ANY
RequestMethod: POST
Request URL: "https://ORCHESTRATOR_HOSTNAME/api/Account/Authenticate"
Body:
AcceptFormat: ANY
RequestMethod: POST
Request URL: "https://ORCHESTRATOR_HOSTNAME/api/Account/Authenticate"
Body:
@"{ " + "\n" + @"""tenancyName"":""TENANT_NAME"", " + "\n" + @"""usernameOrEmailAddress"":""USERNAME"", " + "\n" + @"""password"":""PASSWORD"" " + "\n" + @"}";
Body Format: application/json
Response content: Create a new variable (Ctrl + k) named ResponseResults
Response content: Create a new variable (Ctrl + k) named ResponseResults
Example:
- The rest of the activities have the same approach as the VB project from above.