Created
June 19, 2019 05:21
-
-
Save mrbkdad/3f10290ab13637e4c5d9957cf6354dd5 to your computer and use it in GitHub Desktop.
UiPath Orchestrator API by python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import requests, json\n", | |
"from bs4 import BeautifulSoup" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 172, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def getAuthKey(url,tenancyName,userName,password):\n", | |
" # api_url = \"https://platform.uipath.com/jwpark/jwpark:443\"\n", | |
" data = {\n", | |
" \"tenancyName\": tenancyName,\n", | |
" \"usernameOrEmailAddress\": userName,\n", | |
" \"password\": password\n", | |
"\n", | |
" }\n", | |
" sess = requests.Session()\n", | |
" req = requests.post(url+\"/api/Account/Authenticate\",data)\n", | |
" if(req.status_code == 200):\n", | |
" resJson = req.json()\n", | |
" return resJson[\"result\"]\n", | |
" else:\n", | |
" return None\n", | |
"\n", | |
"def postUiPathAPI(url,key,data):\n", | |
" # api_url = \"https://platform.uipath.com/jwpark/jwpark:443\"\n", | |
" head = {\n", | |
" \"Content-Type\" : \"application/json\",\n", | |
" \"Authorization\" : \"Bearer \" + key\n", | |
" }\n", | |
" \n", | |
" req = requests.post(url,json.dumps(data),headers=head)\n", | |
" if(req.status_code == 200 or req.status_code == 201):\n", | |
" return req.json()\n", | |
" else:\n", | |
" print(BeautifulSoup(req.text,'lxml'))\n", | |
" return None\n", | |
"\n", | |
"def getUiPathAPI(url,key):\n", | |
" # api_url = \"https://platform.uipath.com/jwpark/jwpark:443\"\n", | |
" head = {\n", | |
" \"Content-Type\" : \"application/json\",\n", | |
" \"Authorization\" : \"Bearer \" + key\n", | |
" }\n", | |
" \n", | |
" req = requests.get(url,headers=head)\n", | |
" if(req.status_code == 200):\n", | |
" return req.json()\n", | |
" else:\n", | |
" print(BeautifulSoup(req.text,'lxml'))\n", | |
" return None\n", | |
"\n", | |
"def pretty(reqJson):\n", | |
"# print(reqJson)\n", | |
" for k in reqJson:\n", | |
" print(k + \" : \" + str(reqJson[k]))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 176, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'@odata.context': 'https://platform.uipath.com/jwpark/jwpark:443/odata/$metadata#Releases',\n", | |
" '@odata.count': 1,\n", | |
" 'value': [{'Key': '06427f13-1bb4-4a7f-b64c-5300567c912f',\n", | |
" 'ProcessKey': '로봇_테스트01',\n", | |
" 'ProcessVersion': '1.0.1',\n", | |
" 'IsLatestVersion': False,\n", | |
" 'IsProcessDeleted': False,\n", | |
" 'Description': '',\n", | |
" 'Name': '로봇_테스트01_MyEnv01',\n", | |
" 'EnvironmentId': 91456,\n", | |
" 'EnvironmentName': 'MyEnv01',\n", | |
" 'InputArguments': None,\n", | |
" 'QueueDefinitionId': None,\n", | |
" 'QueueDefinitionName': None,\n", | |
" 'Id': 113562,\n", | |
" 'Arguments': {'Input': None, 'Output': None},\n", | |
" 'ProcessSettings': None}]}" | |
] | |
}, | |
"execution_count": 176, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"## Robot Info, Job Info등\n", | |
"## Job 실행\n", | |
"my_endpoint = \"https://platform.uipath.com/jwpark/jwpark:443\"\n", | |
"api_url = {\n", | |
" 'Robots':my_endpoint+\"/odata/Robots\",\n", | |
" \"Jobs\":my_endpoint+\"/odata/Jobs\",\n", | |
" \"Processes\":my_endpoint+\"/odata/Processes\",\n", | |
" \"Releases\":my_endpoint+\"/odata/Releases\"\n", | |
"}\n", | |
"key = getAuthKey(my_endpoint,\"jwpark\",\"admin\",\"input your password\")\n", | |
"res = getUiPathAPI(api_url[\"Releases\"],key)\n", | |
"res" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 177, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{'@odata.context': 'https://platform.uipath.com/jwpark/jwpark:443/odata/$metadata#Jobs', 'value': [{'Key': '7aeae515-790c-4804-a622-89252e5946bf', 'StartTime': None, 'EndTime': None, 'State': 'Pending', 'Source': 'Manual', 'SourceType': 'Manual', 'BatchExecutionKey': 'c54c3b5e-8b30-462a-b841-ae0956d86fc3', 'Info': None, 'CreationTime': '2019-06-19T05:16:19.7163352Z', 'StartingScheduleId': None, 'ReleaseName': '로봇_테스트01_MyEnv01', 'Type': 'Unattended', 'InputArguments': None, 'OutputArguments': None, 'HostMachineName': None, 'HasMediaRecorded': False, 'Id': 10520273}]}\n" | |
] | |
} | |
], | |
"source": [ | |
"## Job 실행\n", | |
"my_endpoint = \"https://platform.uipath.com/jwpark/jwpark:443\"\n", | |
"\n", | |
"key = getAuthKey(my_endpoint,\"jwpark\",\"admin\",\"input your password\")\n", | |
"# print(reqResult)\n", | |
"\n", | |
"data = {\n", | |
" \"startInfo\": {\n", | |
" \"ReleaseKey\": \"06427f13-1bb4-4a7f-b64c-5300567c912f\",\n", | |
" \"Strategy\": \"Specific\",\n", | |
" \"RobotIds\": [166814],\n", | |
" \"NoOfRobots\": 0,\n", | |
" \"JobsCount\": 0,\n", | |
" \"Source\": \"Manual\",\n", | |
" \"InputArguments\": None\n", | |
" }\n", | |
"}\n", | |
"res = postUiPathAPI(my_endpoint+\"/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs\",key,data)\n", | |
"print(res)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 141, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"xJxJQDP-W90gR7aGR95Rg_7yOHiZU_fdDOIS08xamkvgyOLBofAMedDLXpEarAk8ItdcH-WrJI_11soO0_-_3EbIa_LNfwFWK1Q3xf3PrVEg8hS972VYYQqm785a_9rkEkKr5Xb81wP3jMJZ0GI4GICxN3cruT-vO7qyq3eUYQZpnE70Szz8K-JdREpZZoLCtBU2nogqN_bKKp439xYfY8SRhaF_GfxVJBURztF0jmp8y4CoZv8pxyQF_7NRp4_sSbqo5TZCLAhIYHflTngtnHq67y4H-TNzVzDwRfmPZWY8fNDssPMtWzMtaYoSQc-xsYZgzylPVl06fcQJxI9osZbWx7Igrs9HJu2yB1TOTK6eCwj5opXXngt9kURCJe_0qHj7tHESp1Q4B5d0TE5zkORkBlDWgcaobeaz4vlpdoioANXQB9mcOAoEG6TRPPZJZjHipFi62_7qCJRCi-VOoiA6DP2Wyw9yXKmnzWHBROx1Wbhkcr2zYm2Jds_pmgGSx8p0gZDK2geFrRSyDMhLltb22e2LQAWEbwpOS8qKzkWwNcSbUGk6NyLaXyNffMpA\n", | |
"********** Robots Info\n", | |
"@odata.context : https://platform.uipath.com/jwpark/jwpark:443/odata/$metadata#Robots\n", | |
"@odata.count : 1\n", | |
"value : [{'LicenseKey': None, 'MachineName': 'WIN-UPT62LUQPN7', 'MachineId': 152104, 'Name': 'ROBOT007', 'Username': 'win-upt62luqpn7\\\\administrator', 'Description': None, 'Version': '19.5.0.0', 'Type': 'Development', 'HostingType': 'Standard', 'Password': None, 'CredentialType': None, 'RobotEnvironments': 'MyEnv01', 'Id': 166814, 'ExecutionSettings': None}]\n", | |
"********** Jobs Info\n", | |
"@odata.context : https://platform.uipath.com/jwpark/jwpark:443/odata/$metadata#Jobs\n", | |
"@odata.count : 6\n", | |
"value : [{'Key': 'c4073df3-a32d-4dcb-9acf-1bf40b8d55fb', 'StartTime': '2019-05-30T02:36:50.22Z', 'EndTime': '2019-05-30T02:36:56.513Z', 'State': 'Successful', 'Source': 'Manual', 'SourceType': 'Manual', 'BatchExecutionKey': '5b0a1687-15f6-48fe-9b0e-fc020e00b0b0', 'Info': 'Job completed', 'CreationTime': '2019-05-30T02:36:49.08Z', 'StartingScheduleId': None, 'ReleaseName': '로봇_테스트01_MyEnv01', 'Type': 'Unattended', 'InputArguments': None, 'OutputArguments': '{}', 'HostMachineName': 'WIN-UPT62LUQPN7', 'HasMediaRecorded': False, 'Id': 9545238}, {'Key': '544764d6-ffca-4d80-9ec0-9a61d27cabc7', 'StartTime': '2019-06-19T04:13:39.057Z', 'EndTime': '2019-06-19T04:13:48.087Z', 'State': 'Successful', 'Source': 'Manual', 'SourceType': 'Manual', 'BatchExecutionKey': '1cceff87-ce4f-4b4e-bdca-5efc01bed725', 'Info': 'Job completed', 'CreationTime': '2019-06-19T04:13:37.79Z', 'StartingScheduleId': None, 'ReleaseName': '로봇_테스트01_MyEnv01', 'Type': 'Unattended', 'InputArguments': None, 'OutputArguments': '{}', 'HostMachineName': 'WIN-UPT62LUQPN7', 'HasMediaRecorded': False, 'Id': 10518210}, {'Key': '62fbd46b-0b23-43b6-89c8-b40b1b5d7590', 'StartTime': '2019-06-19T04:22:07.68Z', 'EndTime': '2019-06-19T04:22:10.123Z', 'State': 'Successful', 'Source': 'Manual', 'SourceType': 'Manual', 'BatchExecutionKey': '97f464b3-c109-415e-98d7-fa84b8b856da', 'Info': 'Job completed', 'CreationTime': '2019-06-19T04:22:06.673Z', 'StartingScheduleId': None, 'ReleaseName': '로봇_테스트01_MyEnv01', 'Type': 'Unattended', 'InputArguments': None, 'OutputArguments': '{}', 'HostMachineName': 'WIN-UPT62LUQPN7', 'HasMediaRecorded': False, 'Id': 10518496}, {'Key': 'c19cba9f-e184-460d-beb2-673aad1d6bfc', 'StartTime': '2019-06-19T04:28:32.063Z', 'EndTime': '2019-06-19T04:28:34.593Z', 'State': 'Successful', 'Source': 'Manual', 'SourceType': 'Manual', 'BatchExecutionKey': '26d06141-4907-4f42-8d06-81b7052a7279', 'Info': 'Job completed', 'CreationTime': '2019-06-19T04:28:30.447Z', 'StartingScheduleId': None, 'ReleaseName': '로봇_테스트01_MyEnv01', 'Type': 'Unattended', 'InputArguments': None, 'OutputArguments': '{}', 'HostMachineName': 'WIN-UPT62LUQPN7', 'HasMediaRecorded': False, 'Id': 10518651}, {'Key': 'f9a51aa0-fc26-4f30-9918-2efc63e3b802', 'StartTime': '2019-06-19T04:28:57.427Z', 'EndTime': '2019-06-19T04:29:00.287Z', 'State': 'Successful', 'Source': 'Manual', 'SourceType': 'Manual', 'BatchExecutionKey': '9f21b0e3-4303-4474-98ca-0e1b6c2ff168', 'Info': 'Job completed', 'CreationTime': '2019-06-19T04:28:56.487Z', 'StartingScheduleId': None, 'ReleaseName': '로봇_테스트01_MyEnv01', 'Type': 'Unattended', 'InputArguments': None, 'OutputArguments': '{}', 'HostMachineName': 'WIN-UPT62LUQPN7', 'HasMediaRecorded': False, 'Id': 10518654}, {'Key': 'd8b52045-25af-4e7e-9a79-e8ceaceb954f', 'StartTime': '2019-06-19T04:50:53.617Z', 'EndTime': '2019-06-19T04:50:56.677Z', 'State': 'Successful', 'Source': 'Manual', 'SourceType': 'Manual', 'BatchExecutionKey': 'c22b16d7-bf97-4717-8f44-06b67498c1ae', 'Info': 'Job completed', 'CreationTime': '2019-06-19T04:50:52.697Z', 'StartingScheduleId': None, 'ReleaseName': '로봇_테스트01_MyEnv01', 'Type': 'Unattended', 'InputArguments': None, 'OutputArguments': '{}', 'HostMachineName': 'WIN-UPT62LUQPN7', 'HasMediaRecorded': False, 'Id': 10519402}]\n", | |
"********** Processes Info\n", | |
"@odata.context : https://platform.uipath.com/jwpark/jwpark:443/odata/$metadata#Processes\n", | |
"@odata.count : 1\n", | |
"value : [{'IsActive': False, 'Title': None, 'Version': '1.0.1', 'Key': '로봇_테스트01:1.0.1', 'Description': '첫번째 프로세스', 'Published': '2019-05-30T02:34:46.813Z', 'IsLatestVersion': True, 'OldVersion': None, 'ReleaseNotes': '테스트 프로세스 생성', 'Authors': 'Administrator', 'Id': '로봇_테스트01', 'Arguments': {'Input': None, 'Output': None}}]\n", | |
"********** Releases Info\n", | |
"@odata.context : https://platform.uipath.com/jwpark/jwpark:443/odata/$metadata#Releases\n", | |
"@odata.count : 1\n", | |
"value : [{'Key': '06427f13-1bb4-4a7f-b64c-5300567c912f', 'ProcessKey': '로봇_테스트01', 'ProcessVersion': '1.0.1', 'IsLatestVersion': False, 'IsProcessDeleted': False, 'Description': '', 'Name': '로봇_테스트01_MyEnv01', 'EnvironmentId': 91456, 'EnvironmentName': 'MyEnv01', 'InputArguments': None, 'QueueDefinitionId': None, 'QueueDefinitionName': None, 'Id': 113562, 'Arguments': {'Input': None, 'Output': None}, 'ProcessSettings': None}]\n" | |
] | |
} | |
], | |
"source": [ | |
"## robot,job,process 정보 읽어오기\n", | |
"api_url = \"https://platform.uipath.com/jwpark/jwpark:443\"\n", | |
"data = {\n", | |
" \"tenancyName\": \"jwpark\",\n", | |
" \"usernameOrEmailAddress\": \"admin\",\n", | |
" \"password\": \"input your password\"\n", | |
"\n", | |
"}\n", | |
"sess = requests.Session()\n", | |
"req = requests.post(api_url+\"/api/Account/Authenticate\",data)\n", | |
"resJson = req.json()\n", | |
"reqResult = resJson[\"result\"]\n", | |
"print(reqResult)\n", | |
"head = {\n", | |
" \"Content-Type\" : \"application/json\",\n", | |
" \"Authorization\" : \"Bearer \" + reqResult\n", | |
"}\n", | |
"\n", | |
"print(\"********** Robots Info\")\n", | |
"req = requests.get(api_url+\"/odata/Robots\",headers=head)#?$filter=Name eq 'ROBOT007'\",headers=head)\n", | |
"if(req.status_code == 200):\n", | |
" pretty(req.json())\n", | |
"else:\n", | |
" print(req)\n", | |
"\n", | |
"print(\"********** Jobs Info\")\n", | |
"req = requests.get(api_url+\"/odata/Jobs\",headers=head)#?$filter=Name eq 'ROBOT007'\",headers=head)\n", | |
"if(req.status_code == 200):\n", | |
" pretty(req.json())\n", | |
"else:\n", | |
" print(req)\n", | |
"\n", | |
"print(\"********** Processes Info\")\n", | |
"req = requests.get(api_url+\"/odata/Processes\",headers=head)#?$filter=Name eq 'ROBOT007'\",headers=head)\n", | |
"if(req.status_code == 200):\n", | |
" pretty(req.json())\n", | |
"else:\n", | |
" print(req)\n", | |
" \n", | |
"print(\"********** Releases Info\")\n", | |
"req = requests.get(api_url+\"/odata/Releases\",headers=head)#?$filter=Name eq 'ROBOT007'\",headers=head)\n", | |
"if(req.status_code == 200):\n", | |
" pretty(req.json())\n", | |
"else:\n", | |
" print(req)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment