问题描述
我正在尝试通过 Google Appscript 在协调器中启动 UIPath 作业。
我设置了无人值守的机器人,如果我在协调器中或通过我的助手手动启动工作,它就可以正常工作。 但是当我尝试用脚本启动它时,它失败了。实际上,我正在尝试执行以下文档中第 6.2 和 6.3 段中描述的操作:
https://dev.joget.org/community/display/DX7/Integration+with+UiPath+Robotic+Process+Automation(当然还有后来的 6.4 :))
这是我的代码:
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'];
var header2 = {
'method': 'get','Accept': 'application/json','Authorization': 'Bearer ' + access_token
};
var response2 =
UrlFetchApp.fetch("https://cloud.uipath.com/{Accountlogicalname}/{tenantname}/orchestrator_/odata/Releases?$filter=ProcessKey%20eq%20%27ProcessName%27",header2);
var messageContent2 = response2.getContentText();
var result2 = JSON.parse(messageContent2);
}
我毫无问题地获得了访问令牌。奇怪的部分是函数 processReleaseKey() 中的“fetch”方法。我通过记录“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
}
更奇怪的是,我可以在 Postman 或 cmd 中执行这些任务(甚至像文档 6.4 中那样开始工作)而不会出现任何问题。
希望大家帮帮我。
解决方法
所以这种结构在某种程度上是不可接受的。第二个请求的标头必须如下所示: var header2 = { '方法':'获取', 标题:{ 接受:'应用程序/json', contentType: 'application/json;odata.metadata=minimal;odata.streaming=true',授权:'承载'+ accessToken } };