Starting a UIPath Job via Google Appscript

Hi Guys,

I am trying to start a UIPath-Job in the orchestrator via a Google Appscript.

I set up my unattended Robot and it is working fine, if I start the job manually in the orchestrator or via my assistant .
But when I try to start it with a script, it fails. Actually I am trying to do what is described in the following documentation in paragraph 6.2 and 6.3:

Integration with UiPath Robotic Process Automation - Knowledge Base for DX 7 - Joget | COMMUNITY (and later on of course 6.4 :slight_smile: )

Here is my code:

function authenticateForAT () {
var data1 = {
‘grant_type’: ‘refresh-token’,
‘client_id’: ‘$ClientID’,
‘refresh_token’: ‘$UserKey’,
};
var header1 = {
‘method’: ‘post’,
‘contentType’: ‘application/json’,
‘payload’: JSON.stringify(data1)
};
var response1 = UrlFetchApp.fetch(“https://account.uipath.com/oauth/token”, header1);
var messageContent1 = response1.getContentText();
var result1 = JSON.parse(messageContent1);
var access_token = result1[‘access_token’];
processReleaseKey(access_token);

function processReleaseKey(access_token){
var header2 = {
‘method’: ‘get’,
‘Accept’: ‘application/json’,
‘Authorization’: 'Bearer ’ + access_token
};
var response2 = UrlFetchApp.fetch(“UiPath”", header2);
var messageContent2 = response2.getContentText();
var result2 = JSON.parse(messageContent2);
}

I get the access token without a problem. The bizarre part is the “fetch” method in function processReleaseKey(). I get this message from logging “response2”:
{“message”:“You are not authenticated!”,“errorCode”:0,“result”:null,“targetUrl”:null,“success”:false,“error”:{“code”:0,“message”:“You are not authenticated!”,“details”:“You should be authenticated (sign in) in order to perform this operation.”,“validationErrors”:null},“unAuthorizedRequest”:true,"__abp":true}

Even more bizarre is that I can perform these tasks (and even start the job like in 6.4 of the docu) without any problems in Postman or in the cmd.

I hope you guys can help me.

1 Like

Hi @Philip1,

That is cool, using google scripts you may we be on your way to trigger robots from spreadsheets :slight_smile: Google script is fun.

I cant see your processReleaseKey function calling having the correct header (header2)
X-UIPATH-OrganizationUnitId

See more here for modern folders and release key: UiPath Connector Guide

That is weird that you can run the same flow in Postman and CMD :face_with_monocle:

Thank you for your quick response! Yeah, that is my intention to trigger it from a spreadsheet :smile: .
I tried adding X-UIPATH-OrganisationUnitID and/or X-UIPATH-TenantName to header2, unfortunately without success…

I solved the problem. Actually header2 was just badly structured:
var header2 = {
‘method’: ‘get’,
headers: {
accept: ‘application/json’,
contentType: ‘application/json;odata.metadata=minimal;odata.streaming=true’,
authorization: 'Bearer ’ + accessToken
}
};
If it looks like this, it works…

1 Like

Hi @Philip1,

Time to design some fancy buttons to press :wink:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.