通过 Google Apps 脚本启动 UIPath 作业

Starting a UIPath Job via Google Appscript

我正在尝试通过 Google Appscript 在编排器中启动 UIPath-Job。

我设置了无人值守的机器人,如果我在协调器中或通过我的助手手动启动作业,它工作正常。 但是当我尝试用脚本启动它时,它失败了。实际上,我正在尝试执行以下文档第 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 中那样开始工作)而没有任何问题。

希望大家帮帮我

所以这个结构在某种程度上是不可接受的。第二个请求中的 header 必须如下所示: var header2 = { 'method': 'get', header秒:{ 接受:'application/json', 内容类型:'application/json;odata.metadata=minimal;odata.streaming=true', 授权:'Bearer ' + accessToken } };