0

I am trying to obtain the authentication token from the Processmaker to use the APIs. I have used the same API call which works perfectly fine in the test environment, with production urls and respective client id and client secret. But, I am getting below error, although the username and password of the account is correct.

Request:

{
    "grant_type": "password",
    "scope": "*",
    "client_id": "xxxxxx",
    "client_secret":"7777777",
    "username": "username",
    "password": "password"
}

Response:

{
    "error": "invalid_client",
    "error_description": "The client credentials are invalid"
}

I have tried below steps. But still the same error.

  1. Create a new account without AD user account as the account used in test environment is not a domain account
  2. Change the role of account to 'System Administrator' which is similar to the account in test

**While registering the client to use the APIs, we didn't use the Callback URL as it is optional (we did not configure it in the test environment as well)

Some help is really appreciated, as I have no clue what else to check between the environment to resolve this issue.

udani
  • 1,243
  • 2
  • 11
  • 33

1 Answers1

1

I am not sure if you are trying to call API from ProcessMaker to RPA or RPA to ProcessMaker.

For ProcessMaker to RPA:

Using Script: I have built a ProcessMaker script in PHP and with appropriate script configuration, you will be able to run the RPA bot from ProcessMaker.

<?php 

/*  
 *  Yo. This script is developed by Abhishek Kadam.
 *  This script is sufficient to run all the Microbots. 
 *  The Script Configuration contains "release_key" which is the Process ID,
 *  "robot_id" which is to identify where to run the Bot, "orch_unit_id" which is the folder name
 *  and "orch_url" which stands for Orchestrator URL. To Run the bot, All the configurations are required. 
 */


//******ASSIGNING VARIABLES*****
$client_id = $config['client_id'];   // $config to get data from Script Configuration
$refresh_token = $config['refresh_token'];
$release_key = $config['release_key'];
$robot_id = $config['robot_id'];
$orch_url = $config['orch_url'];
$orch_unit_id = $config["orch_unit_id"];




//****** GET ACCESS TOKENS USING CLIENT ID AND REFRESH TOKENS******
$access_token = getAccessToken($client_id,$refresh_token);
$output_response = runBot($access_token,$release_key,$robot_id,$orch_url,$orch_unit_id);   
//pass the Access token to runbot() and run the bot ez-pz! 




function getAccessToken($client_id,$refresh_token){
  $curl = curl_init();
  curl_setopt_array($curl, array(
    CURLOPT_URL => "https://account.uipath.com/oauth/token",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS =>"{\r\n    \"grant_type\": \"refresh_token\",\r\n    \"client_id\": \"".$client_id."\",\r\n    \"refresh_token\": \"".$refresh_token."\"\r\n}",
    CURLOPT_HTTPHEADER => array(
      "Content-Type: application/json"
    ),
  ));
  
  $response = curl_exec($curl);

  curl_close($curl);


  $responseDecode = json_decode($response);
  $accessToken= $responseDecode -> access_token;  //get the access token
  return $accessToken;
}



function runBot($access_token,$release_key,$robot_id,$orch_url,$orch_unit_id){
  
  $curl = curl_init();  //Not sure if it's the right way to initialize or not but meh, it works :P 

 

  curl_setopt_array($curl, array(
    CURLOPT_URL => $orch_url."/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS =>"{ \"startInfo\":\r\n   { \"ReleaseKey\": \"".$release_key."\",\r\n     \"Strategy\": \"Specific\",\r\n     \"RobotIds\": [ ".$robot_id."],\r\n     \"JobsCount\": 0,\r\n     \"Source\": \"Manual\" \r\n   } \r\n}",
    // Release key and Robot ID can be concatenated and passed as an argument(once I figure out how to get arguments in PM 4 scripts)
    CURLOPT_HTTPHEADER => array(
      "Content-Type: application/json",
      "Authorization: Bearer ".$access_token,
      "X-UIPATH-OrganizationUnitId: ".$orch_unit_id

    //There's another way to use the Access token. For now, I found this more helpful.
    //As the document is TL;DR. https://www.php.net/manual/en/function.curl-setopt.php
    
    ),
  ));

  $response = curl_exec($curl);
  curl_close($curl);
  return $response;
//echo $response; //Print Response cuz why not? ;) 
}
 return [$access_token];


?>

I had used the UiPath RPA tool for this without mentioning any callback URL.

Using Data Connectors: Create Data Connectors in ProcessMaker. I prefer to using the Postman application before creating DC. Refer: Postman to UiPath Bot

For RPA Bot to ProcessMaker In ProcessMaker documentation you can see the Swagger Link for your particular instance. The Swagger Documentation for ProcessMaker was not really helpful. There are few mistakes in the documentation provided. For ease, I did import the API collection in Postman and proceeded with creating variables: baseURL & accessToken

baseURL: Your URL (https://something.processmaker.net)

ADD /api/1.0

/api/1.0 (https://something.processmaker.net/api/1.0)

Now the URL is correct. Also while sending the request make sure Params are not empty.

Note: For Access Token, Admin --> Users --> Edit --> API Tokens --> Create new Token --> Copy Token. In Processmaker 4, API tokens are available for individual Users.

I hope this will help you in a way. Thanks!