Step By Step Guide in order to trigger the UI Path Bot through API
Getting Token to Use in Your API Calls
Generating Code Challenge and Code Verifier
- In a web browser window, go to Node.js Online Compiler & Interpreter - Replit.
- Paste the following code in the index.js file:
function base64URLEncode(str) {
return str.toString(‘base64’)
.replace(/+/g, ‘-’)
.replace(///g, ‘_’)
.replace(/=/g, ‘’);
}
function sha256(buffer) {
return crypto.createHash(‘sha256’).update(buffer).digest();
}
console.log(“Generating challenge and Verifier”);
var cryptoResult = crypto.randomBytes(32);
var verifier = base64URLEncode(cryptoResult);
var challenge = base64URLEncode(sha256(verifier));
console.log("Code challenge: " + challenge)
console.log("Code verifier: " + verifier);
-
Click Run on the top of the page. The output should look like this:
Generating challenge and Verifier
Code challenge: 6FmSWYSNC1I-7fC6oTIEGz-FirleVDkAVjxkkbYNzc4
Code verifier: IwqVfyjRULvl5Yz9S8InPTVqZTlfJn5MysOOOZrXDKs -
Save the codes.
Getting Authorization Code
- Copy the following URL in a text editor, such as Notepad:
UiPath[Code Challenge]&code_challenge_method=S256&scope=openid+profile+offline_access+email &audience=https%3A%2F%2Forchestrator.cloud.uipath.com&client_id=5v7PmPJL6FOGu6RB8I1Y4adLBhIwovQN&redirect_uri=https%3A%2F%2Faccount.uipath.com%2Fmobile - Replace [Code challenge] with your Code challenge generated in step 3 of the previous section.
- Copy the updated URL.
- Open a web browser window.
- Paste the updated URL into the address bar, and press Enter. You are redirected to a UiPath Login page.
- Login using your credentials.
- The browser’s Text window shows OK, with the URL in the following format:
https://account.uipath.com/mobile?code=[Authorization code]&state=47441df4d0f0a89da08d43b6dfdc4be2 - Copy this [Authorization code] for later use.
Getting Refresh Token
- In any API testing tool, perform a POST request to the https://account.uipath.com/oauth/token URL. In the body of the request, replace [Authorization code] and [Code verifier] with the values received in the two procedures above. The request and response should look as in the following example
POST https://account.uipath.com/oauth/token
Request
Content-Type: application/json
{
“grant_type”: “authorization_code”,
“code”: “[Authorization code]”,
“redirect_uri”: “https://account.uipath.com/mobile”,
“code_verifier”: “[Code verifier]”,
“client_id”: “5v7PmPJL6FOGu6RB8I1Y4adLBhIwovQN”
}
Response
Content-Type: application/json
{
“access_token”: “[access token]”,
“refresh_token”: “[refresh token]”,
“id_token”: “[id token]”,
“scope”: “openid profile email offline_access”,
“expires_in”: 86400,
“token_type”: “Bearer”
}
- Copy the [refresh_token] from the body of the response for later use.
Generating Access Token and ID Token Using the Refresh Token
Important!
The [access_token] required for making API calls is valid for 24 hours. You have to regenerate [access_token] and [id_token] using your [refresh_token], otherwise you receive 401 status code.
- In any API testing tool, perform a POST request to the https://account.uipath.com/oauth/token URL. In the body of the request, replace [refresh_token] with the refresh_token value received in the procedure above. The request and response should look as in the following example:
POST https://account.uipath.com/oauth/token
Request
Content-Type: application/json
{
“grant_type”: “refresh_token”,
“client_id”: “5v7PmPJL6FOGu6RB8I1Y4adLBhIwovQN”,
“refresh_token”: “[refresh token]”
}
Response
Content-Type: application/json
{
“access_token”: “[access token]”,
“id_token”: “[id token]”,
“scope”: “openid profile email offline_access”,
“expires_in”: 86400,
“token_type”: “Bearer”
}
- Copy [access_token] and [id_token] for later use.
Discovering UiPath Account and Service Instance Identifiers
Getting Account Logical Name
- In any API testing tool, perform a GET request to the UiPath URL. You need to use Authorization header with your Bearer Token, pasting the [id_token]value received in the procedure above. The request and response should look as in the following example:
GET UiPath
Request
Authorization: Bearer [id_token]
Response
Content-Type: application/json
{
“userEmail”: “[user_email]”,
“accounts”: [
{
“accountName”: “[account_name]”,
“accountLogicalName”: “[account_logical_name]”
}
]
}
- Copy [account_logical_name] for later use.
Getting Service Instance Logical Name
- Copy the following URL into API testing tool, to perform a GET request: UiPath
- Replace the [account_logical_name] with the value obtained in the procedure above.
- You need to use Authorization header with your Bearer Token, pasting the [id_token] value received in the procedure above.
The request and response should look as in the following example:
GET UiPath
Request
Authorization: Bearer [id_token]
Response
Content-Type: application/json
[
{
“serviceInstanceName”: “[service_instance_name]”,
“serviceInstanceLogicalName”: “[service_instance_logical_name]”,
“serviceType”: “ORCHESTRATOR”,
“serviceUrl”: “[service_url]”
}
]
- Copy [service_instance_logical_name] for later use.
Important!
All Orchestrator API calls subsequent to the initial authorization have to contain the following headers:
Authorization: Bearer [access_token]
X-UIPATH-TenantName: [service_instance_logical_name]
Below api is used to get all the process available inyour community edition:
Get
https://platform.uipath.com/{Account_logical_name}/{Service_instance_logical_name}/odata/Releases
below headers are mandatory in order to call any API.
Authorization: Bearer [access_token]
Content-Type: application/json
X-UIPATH-TenantName: [service_instance_logical_name]
Response:
{
“@odata.context”: “https://platform.uipath.com/isbglobal/ISBglobalDe85sa223806/odata/$metadata#Releases”,
“@odata.count”: 1,
“value”: [
{
“Key”: “xxxx-x-xxx-xx-xxxxx”,
“ProcessKey”: “ProcessKey”,
“ProcessVersion”: “1.0.2”,
“IsLatestVersion”: false,
“IsProcessDeleted”: false,
“Description”: “”,
“Name”: “EnvironmentName”,
“EnvironmentId”: 44914,
“EnvironmentName”: “EnvironmentName”,
“InputArguments”: null,
“Id”: 46314,
“Arguments”: {
“Input”: null,
“Output”: null
},
“ProcessSettings”: null
}
]
}
final API in order to trigger your Bot through API
Note: you need to pass the key of process you receveid in previous API, that it you are done.
Request:
{
“startInfo”: {
“ReleaseKey”: “[release key]”,
“Strategy”: “All”,
“RobotIds”: ,
“NoOfRobots”: 0
}
}