如何通过REST API从ServiceNow启动UiPath机器人

问题描述 投票:1回答:2

如何启动与UiPath Orchestrator连接的UiPath Robot?我想从ServiceNow接口将REST API命令发送到Orchestrator。

rest scripting servicenow uipath snow
2个回答
0
投票

答案可以在Youtube的这两部电影中找到:

从POSTMAN配置和测试命令:https://www.youtube.com/watch?v=84Wlzn1CK_Y

从ServiceNow发送命令:https://www.youtube.com/watch?v=GYqaWoT7Xxk

这是来自ServiceNow的脚本代码:

var testDEMO = Class.create();
testDEMO.prototype = {
    initialize: function() {
    },
test: function(param1,param2)
    {       
    var rm = new sn_ws.RESTMessageV2();
    rm.setHttpMethod('post');
    rm.setEndpoint('https://account.uipath.com/oauth/token');
    rm.setRequestHeader('Content-Type', 'application/json');
    rm.setRequestHeader('X-UIPATH-TenantName', 'YOUR TENANTNAME');

 var params = {
    'grant_type': 'refresh_token',
    'client_id': 'YOUR CLIENT ID',
    'refresh_token': 'YOUR REFRESH TOKEN'
  };

var json = new JSON();
var text = json.encode(params);
rm.setRequestBody(text);
var response = rm.execute();

var body = response.getBody();

var auth = body.substring(body.indexOf('access_token')+15, body.indexOf('id_token')-3);

        gs.info("Body:  "+response.getBody());
        gs.info("Auth:  "+auth);

var rm2 = new sn_ws.RESTMessageV2();
    rm2.setHttpMethod('post');  
    rm2.setEndpoint('https://platform.uipath.com/[Account Logical Name]/[Tenant Logical Name]/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs'); 
    rm2.setRequestHeader('Content-Type', 'application/json');
    rm2.setRequestHeader('X-UIPATH-TenantName', 'YOUR TENANTNAME');
    rm2.setRequestHeader('Authorization', 'Bearer '+auth);
    rm2.setRequestHeader('User-Agent','telnet');    

//how to start a simple process without parameters  
/*var params3 = {};
params3.ReleaseKey ='YOUR PROCESS ReleaseKey';
params3.Strategy = 'All';

var params2 = {};
params2.startInfo = params3;*/

//How to start a process with parameters

var params3 = {};
params3.ReleaseKey ='YOUR PROCESS ReleaseKey';
params3.Strategy = 'All';
params3.InputArguments ='{"param1":"'+param1+'","param2":"'+param2+'"}';

var params2 = {};
params2.startInfo = params3;

var json2 = new JSON();
var text2 = json2.encode(params2);
rm2.setRequestBody(text2);
var response2 = rm2.execute();

gs.info("Body:  "+response2.getBody());
return response2.getBody();     
    },
    type: 'testDEMO'
};

0
投票

首先获取您的架构的个人网址

https://platform.uipath.com/[account_logical_name]/[service_instance_logical_name] ...

总体上,您需要请求它以获取逻辑名:https://platform.uipath.com/cloudrpa/api/getAccountsForUser

这里是执行此操作的步骤:

  1. 在浏览器中运行JavaScript代码,这将为您提供代码挑战和代码验证器。

  2. 用代码质询修改account.uipath.com URL,并在浏览器本身中发送请求。它将要求您使用凭据进行身份验证。您需要在浏览器中传递此URL,浏览器URL会返回授权码。

  3. 然后您需要使用正文将请求发送到https://account.uipath.com/oauth/token

  4. 您将获得承载令牌。

  5. 您需要获取逻辑名,因此再次请求输入https://platform.uipath.com/cloudrpa/api/getAccountsForUser,您将获得名称。

  6. 使用所有这些,尝试再次发送请求。

[当您需要更多帮助时,请查看几个链接,因为它们在例如邮递员:

© www.soinside.com 2019 - 2024. All rights reserved.