UiPath Orchestrator接口(API)方式启动流程(作业)
以API的方式调用机器人开始作业
原文来自: How To Start A Job In PowerShell Using Orchestrator API Endpoints?
中文互联网上似乎没有找到相关资料,有一篇似乎是以前的,现在不适用了,故写下本文。
前言
所有接口调试基于Postman
需要用到的接口:{{url}}为:https://cloud.uipath.com/用户名/租户名,如:https://cloud.uipath.com/admin/DefaultTenant
- https://cloud.uipath.com/identity_/connect/token
- {{url}}/orchestrator_/odata/Folders
- {{url}}/orchestrator_/odata/Folders/UiPath.Server.Configuration.OData.GetMachinesForFolder(key={{folderID}})
- {{url}}/orchestrator_/odata/Robots/UiPath.Server.Configuration.OData.GetConfiguredRobots
- {{url}}/orchestrator_/odata/Releases
- {{url}}/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs
一、概述
使用指定文件夹下的指定机器上的指定的机器人执行指定流程(作业):
- OC上启用External Applications(外部应用);
- 通过External Applications获取到access_token;
- 通过access_token查询到文件夹Id、机器(设备)Id、机器人Id。
二、详细步骤
1.在OC上新建External Applications
- 点击Admin-External Applications-Add Application
- 输入app名称;
选择加密应用(也可以选择不加密,这里没有尝试过,可以尝试一下);
添加应用权限范围-选择Orchestrator API Access,选择Application Scope(s)(User Scope可不选,具体范围我这边也没有深究),点击保存;
设置访问该App的URL:https://cloud.uipath.com/identity_/connect/authorize
- 点击保存后出现这两个App ID、App Secret,
记录下来,如果没有出现弹窗,可点击Edit编辑查看。
2.访问App获取令牌
Request
EndPoint:https://cloud.uipath.com/identity_/connect/token
Type:Post
Headers:Content-Type:application/x-www-form-urlencoded
Body: x-www-form-urlencodedclient_secret:上文提到的App secret
client_id:上文提到的App ID
scope:OR.Settings OR.Queues OR.License OR.Folders OR.Execution OR.Robots OR.Machines OR.Jobs
grant_type:client_credentials
**Reponse**
{
"access_token": "eyJhb此处省略",
"expires_in": 3600,
"token_type": "Bearer",
"scope": "OR.Execution OR.Folders OR.Jobs OR.License OR.Machines OR.Queues OR.Robots OR.Settings"
}
Bearer 加空格加 access_token的内容即为我们所需的Authorization
Bearer eyJhb此处省略
3.获取文件夹ID
-
在OC上确定自己的机器人及机器所在的文件夹
进入Orchestrator,选择指定的文件夹(为新式文件夹),点击Settings,Machines,确认自己机器是否在该文件夹下
如果机器不在该文件夹下,则需要点击右侧Manage Machines in Folder,并选择标准计算机添加
名称为:设备名/账户名 -
发送请求获取ID
Request
EndPoint:{{url}}/orchestrator_/odata/Folders
Type:Get
Headers:Authorization:Bearer eyJhd此处省略
Body: NoneReponse
返回值中的Id即为文件夹ID
{
"@odata.context": "{{自己的URL}}/orchestrator_/odata/$metadata#Folders",
"@odata.count": 1,
"value": [
{
"Key": "此处省略",
"DisplayName": "Shared",
"FullyQualifiedName": "Shared",
"FullyQualifiedNameOrderable": "Shared",
"Description": null,
"ProvisionType": "Automatic",
"PermissionModel": "FineGrained",
"ParentId": null,
"ParentKey": null,
"IsActive": true,
"FeedType": "Processes",
"Id": 数字
}
]
}
4.通过文件夹ID获取机器ID
Request
EndPoint:{{url}}/orchestrator_/odata/Folders/UiPath.Server.Configuration.OData.GetMachinesForFolder(key={{folderID}})
Type:Get
Headers:Authorization:Bearer eyJhd此处省略
Accept:application/json
Body: None
**Reponse**
返回值中的Id即为**机器ID**
{
"@odata.context": "{{自己的URL}}/orchestrator_/odata/$metadata#MachineFolder",
"@odata.count": 1,
"value": [
{
"LicenseKey": null,
"Name": "设备名\\Windows用户名",
"Description": "",
"Type": "Template",
"Scope": "PersonalWorkspace",
"NonProductionSlots": 0,
"UnattendedSlots": 1,
"HeadlessSlots": 0,
"TestAutomationSlots": 0,
"AutomationCloudSlots": 0,
"Key": "标识符",
"AutoScalingProfile": null,
"AutomationType": "Any",
"TargetFramework": "Windows",
"ClientSecret": null,
"Id": 数字,
"IsAssignedToFolder": true,
"HasMachineRobots": false,
"IsInherited": false,
"PropagateToSubFolders": false,
"InheritedFromFolderName": null,
"RobotVersions": [],
"RobotUsers": [],
"UpdatePolicy": null,
"Tags": [],
"MaintenanceWindow": null
}
]
}
5.通过机器ID获取机器人ID
Request
EndPoint:{{url}}/orchestrator_/odata/Robots/UiPath.Server.Configuration.OData.GetConfiguredRobots
Type:Get
Headers:Authorization:Bearer eyJhd此处省略
X-UIPATH-OrganizationUnitId:{{folderID}}
Content-Type:application/json
Body: None
Reponse
返回值中的Id即为机器人ID(注意通过名称确认哪个是自己需要的机器人)
{
"@odata.context": "{{自己的URL}}/orchestrator_/odata/$metadata#ExtendedRobotDto",
"@odata.count": 2,
"value": [
{
"LicenseKey": null,
"MachineName": null,
"MachineId": null,
"Name": "名称-unattended",
"Username": "机器名称(设备名/Windows账户名)",
"ExternalName": null,
"Description": null,
"Type": "Unattended",
"HostingType": "Floating",
"ProvisionType": "Automatic",
"Password": null,
"CredentialStoreId": null,
"UserId": 数字,
"Enabled": true,
"CredentialType": "Default",
"RobotEnvironments": "",
"IsExternalLicensed": false,
"LimitConcurrentExecution": true,
"LastModificationTime": "2022-05-20T15:23:31.287Z",
"LastModifierUserId": 数字,
"CreationTime": "2021-03-18T10:41:28.823Z",
"CreatorUserId": 数字,
"Id": 数字,
"ExecutionSettings": null
}
]
}
6.获取流程Key
import requests
url = “{{自己的URL}}/orchestrator_/odata/Releases”
payload = {}
headers = {
‘accept’: ‘application/json’,
‘X-UIPATH-OrganizationUnitId’: ‘文件夹ID’,
‘Accept’: ‘/’,
‘Authorization’: ‘Bearer eyJhbGw’
}
response = requests.request(“GET”, url, headers=headers, data=payload)
print(response.text)
7.通过令牌、文件夹ID、机器ID、机器人ID启动作业
Request
EndPoint:{{url}}/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs
Type:Get
Headers:Authorization:Bearer eyJhd此处省略
X-UIPATH-OrganizationUnitId:{{folderID}}
Accept:*/*
Body: Raw
{"startInfo": {
"ReleaseKey": "{{processKey}}",
"JobsCount": 1,
"JobPriority": "Normal",
"Strategy": "ModernJobsCount",
"ResumeOnSameContext": false,
"RuntimeType": "Unattended",
"InputArguments": "{'str_taskID':'{{str_taskID}}','str_customerID':'{{str_customerID}}'}",
"MachineRobots": [
{
"RobotId": {{RobotID}},
"MachineId": {{MachineId}}
}
]
}
}
特别需要注明,其中的InputArguments(输入参数)格式为:
“{‘key’:‘value’,‘key’:‘value’}”
Reponse文章来源:https://www.toymoban.com/news/detail-538153.html
{
"@odata.context": "{{自己的URL}}/orchestrator_/odata/$metadata#Jobs",
"value": [
{
"Key": "Key",
"StartTime": null,
"EndTime": null,
"State": "Pending",
"JobPriority": "Normal",
"SpecificPriorityValue": 45,
"Source": "Manual",
"SourceType": "Manual",
"BatchExecutionKey": "Key",
"Info": null,
"CreationTime": "2022-06-21T06:02:52.683Z",
"StartingScheduleId": null,
"ReleaseName": "流程名",
"Type": "Unattended",
"InputArguments": "{\"str_taskID\":\"No.1\",\"str_customerID\":\"No.1\"}",
"OutputArguments": null,
"HostMachineName": null,
"HasMediaRecorded": false,
"PersistenceId": null,
"ResumeVersion": null,
"StopStrategy": null,
"RuntimeType": "Unattended",
"RequiresUserInteraction": true,
"ReleaseVersionId": null,
"EntryPointPath": "Main.xaml",
"OrganizationUnitId": 数字,
"OrganizationUnitFullyQualifiedName": null,
"Reference": "",
"ProcessType": "Process",
"ProfilingOptions": null,
"ResumeOnSameContext": false,
"LocalSystemAccount": "",
"OrchestratorUserIdentity": null,
"Id": 数字
}
]
}
8.查看作业运行状态
我没用过文章来源地址https://www.toymoban.com/news/detail-538153.html
到了这里,关于UiPath Orchestrator接口(API)方式启动流程(作业)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!