How to retrieve the Bearer token from the On-Premise Orchestrator using the HTTP Request Activity via a Basic Authentication?

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

  1. 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:
"{""tenancyName"": ""TENANT_NAME"",""usernameOrEmailAddress"": ""USERNAME"",""password"": ""PASSWORD""}"

Body Format: application/json

Response content: Create a new variable (Ctrl + k) named ResponseResults


Example:

image.png

  1. Add a Deserialize JSON activity as below:
image.png

  1. Add an Assign activity as below:
To: Create a new varible (Ctrl + k) named AccessTokenString
Value:
 "Bearer " + Convert.ToString(AccessToken.GetValue("result"))
image.png
  1. 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

  1. 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:
@"{
" + "\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


Example:

image.png
  1. The rest of the activities have the same approach as the VB project from above.