UiPath API Orchestrator Authentication error

Hi,

I am using the Platform.UiPath.com API to test a front end system I am building. First I have extensively tested all functions in Swagger. Now, I try to use the API in Node and there it does not work unfortunately.

function sendTaskData($parameters) {
/*****************/
$ch = curl_init("https://platform.uipath.com/api/Account?api_key=*********************************************");
    $arr = array("tenancyName"=> "*****","usernameOrEmailAddress"=> "****************","password"=> "**********");
	$headers = array(  'Content-Type: application/json','Accept: application/json' );
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($arr));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		$output = curl_exec($ch);      
		$decodes = json_decode($output);
		curl_close($ch);
   $xsrf_token = $decodes->result;
    // print_r($decodes); die;
/*****************/   


 $request = json_encode(array('itemData' => $parameters)); 
 $ch = curl_init("https://platform.uipath.com/odata/Queues/UiPathODataSvc.AddQueueItem?api_key=*************************");			    
	$headers = array(  'Content-Type: application/json','Accept: application/json',"x-xsrf-token:{$xsrf_token}" );
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
		$output = curl_exec($ch);      
		$result = json_decode($output);
		curl_close($ch);			    
				    
		echo "<pre>"; print_r($result); die;

image

So even though I authenticate my request, it still says Unauthorized when I try to add a Queue item to a queue. Does anyone have any advice how I can proceed from here? I have looked over the forum, made some changes based on that but it still does not work. All help very much appreciated, thx.

Hi,
I don’t have much idea as the format of node.But i have used the API in java and basically after authentication you need to pass the authorization key as part of header with value as “Bearer $auth_key$” for the other API’s.
while testing from swagger things would work as you would have logged in to Platform.UiPath.com.You can use POSTMAN to test the API’s as well where you can get clear idea before using in the code.

Attaching one such POSTMAN instance.

That did the trick! A side solution is that I should have read better :wink: Thanks @Indrajit_Banerjee.