C / Orchestrator / 4. Jobs - Start job with inputs
Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *Key;
const char *StartTime;
const char *EndTime;
const char *State;
const char *Source;
const char *SourceType;
const char *BatchExecutionKey;
const char *Info;
const char *CreationTime;
const char *StartingScheduleId;
const char *ReleaseName;
const char *v_Type;
const char *InputArguments;
const char *OutputArguments;
int Id;
const char *odata_context;
int i;
int count_i;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "startInfo": {
// "ReleaseKey": "5b754c63-5d1a-4c37-bb9b-74b69e4934bf",
// "Strategy": "Specific",
// "RobotIds": [
// 1553
// ],
// "JobsCount": 0,
// "Source": "Manual",
// "InputArguments": "{\"message\":\"Aloha\"}"
// }
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"startInfo.ReleaseKey","5b754c63-5d1a-4c37-bb9b-74b69e4934bf");
CkJsonObject_UpdateString(json,"startInfo.Strategy","Specific");
CkJsonObject_UpdateInt(json,"startInfo.RobotIds[0]",1553);
CkJsonObject_UpdateInt(json,"startInfo.JobsCount",0);
CkJsonObject_UpdateString(json,"startInfo.Source","Manual");
CkJsonObject_UpdateString(json,"startInfo.InputArguments","{\"message\":\"Aloha\"}");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,"<access_token>");
CkHttp_SetRequestHeader(http,"X-UIPATH-OrganizationUnitId","{{folderId}}");
CkHttp_SetRequestHeader(http,"X-UIPATH-TenantName","{{tenantName}}");
resp = CkHttp_PostJson3(http,"https://domain.com/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs","application/json",json);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
return;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "@odata.context": "https://beta.uipath.com/odata/$metadata#Jobs",
// "value": [
// {
// "Key": "b618cdfd-8714-4dbf-9a00-0586a8953c90",
// "StartTime": null,
// "EndTime": null,
// "State": "Pending",
// "Source": "Manual",
// "SourceType": "Manual",
// "BatchExecutionKey": "abbbb5de-d46a-4b9b-8f73-8a3247be0a0e",
// "Info": null,
// "CreationTime": "2018-09-21T13:28:31.1449691Z",
// "StartingScheduleId": null,
// "ReleaseName": "Heyyo_playground",
// "Type": "Unattended",
// "InputArguments": "{\"greeting\":\"Aloha\"}",
// "OutputArguments": null,
// "Id": 160856
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
odata_context = CkJsonObject_stringOf(jResp,"\"@odata.context\"");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"value");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
Key = CkJsonObject_stringOf(jResp,"value[i].Key");
StartTime = CkJsonObject_stringOf(jResp,"value[i].StartTime");
EndTime = CkJsonObject_stringOf(jResp,"value[i].EndTime");
State = CkJsonObject_stringOf(jResp,"value[i].State");
Source = CkJsonObject_stringOf(jResp,"value[i].Source");
SourceType = CkJsonObject_stringOf(jResp,"value[i].SourceType");
BatchExecutionKey = CkJsonObject_stringOf(jResp,"value[i].BatchExecutionKey");
Info = CkJsonObject_stringOf(jResp,"value[i].Info");
CreationTime = CkJsonObject_stringOf(jResp,"value[i].CreationTime");
StartingScheduleId = CkJsonObject_stringOf(jResp,"value[i].StartingScheduleId");
ReleaseName = CkJsonObject_stringOf(jResp,"value[i].ReleaseName");
v_Type = CkJsonObject_stringOf(jResp,"value[i].Type");
InputArguments = CkJsonObject_stringOf(jResp,"value[i].InputArguments");
OutputArguments = CkJsonObject_stringOf(jResp,"value[i].OutputArguments");
Id = CkJsonObject_IntOf(jResp,"value[i].Id");
i = i + 1;
}
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-H "X-UIPATH-TenantName: {{tenantName}}"
-H "X-UIPATH-OrganizationUnitId: {{folderId}}"
-d '{ "startInfo":
{ "ReleaseKey": "5b754c63-5d1a-4c37-bb9b-74b69e4934bf",
"Strategy": "Specific",
"RobotIds": [ 1553 ],
"JobsCount": 0,
"Source": "Manual",
"InputArguments": "{\"message\":\"Aloha\"}"
}
}'
https://domain.com/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs
Postman Collection Item JSON
{
"name": "4. Jobs - Start job with inputs",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
},
{
"key": "X-UIPATH-TenantName",
"value": "{{tenantName}}",
"type": "text"
},
{
"key": "X-UIPATH-OrganizationUnitId",
"value": "{{folderId}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{ \"startInfo\":\r\n { \"ReleaseKey\": \"5b754c63-5d1a-4c37-bb9b-74b69e4934bf\",\r\n \"Strategy\": \"Specific\",\r\n \"RobotIds\": [ 1553 ],\r\n \"JobsCount\": 0,\r\n \"Source\": \"Manual\",\r\n \"InputArguments\": \"{\\\"message\\\":\\\"Aloha\\\"}\"\r\n } \r\n}"
},
"url": {
"raw": "{{url}}/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs",
"host": [
"{{url}}"
],
"path": [
"odata",
"Jobs",
"UiPath.Server.Configuration.OData.StartJobs"
]
},
"description": "Within Orchestrator, a **Process** that is running or has been run is called a **Job**. To start a **Job**, navigate to the body of this call and add the release key obtained in step 2 to the first field.\n\nNow look at the `Strategy` field. This dictates how the process should be run and has 3 options:\n\n 1. _Specific_ - The process will run on a specific set of robots, whose IDs are indicated in the `RobotIds` field.\n 2. _JobsCount_ - The process will run x times where x is the value of the `JobsCount` field. Use this strategy if you don't care on which robots the job runs. Orchestrator will automatically allocate the work to any available robots.\n 3. _All_ - The process will run once on all robots.\n \nLastly, if your job has any input parameters, they can be sent as a JSON string in the `InputArguments` field. If it does not, this field will be ignored."
},
"response": [
{
"name": "Jobs - Start job with inputs",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{ \"startInfo\":\r\n { \"ReleaseKey\": \"0764f4a-2ce0-41b9-r738-4575566f3756\",\r\n \"Strategy\": \"Specific\",\r\n \"RobotIds\": [ 12345 ],\r\n \"NoOfRobots\": 0,\r\n \"Source\": \"Manual\",\r\n \"InputArguments\": \"{\\\"greeting\\\":\\\"Aloha\\\"}\"\r\n } \r\n}"
},
"url": {
"raw": "{{url}}/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs",
"host": [
"{{url}}"
],
"path": [
"odata",
"Jobs",
"UiPath.Server.Configuration.OData.StartJobs"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Access-Control-Expose-Headers",
"value": "Request-Context",
"name": "Access-Control-Expose-Headers",
"description": "Lets a server whitelist headers that browsers are allowed to access."
},
{
"key": "CF-RAY",
"value": "45dce00e5ae5714f-ORD",
"name": "CF-RAY",
"description": "Custom header"
},
{
"key": "Cache-Control",
"value": "no-store, must-revalidate, no-cache, max-age=0",
"name": "Cache-Control",
"description": "Tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds"
},
{
"key": "Connection",
"value": "keep-alive",
"name": "Connection",
"description": "Options that are desired for the connection"
},
{
"key": "Content-Length",
"value": "486",
"name": "Content-Length",
"description": "The length of the response body in octets (8-bit bytes)"
},
{
"key": "Content-Type",
"value": "application/json; odata.metadata=minimal",
"name": "Content-Type",
"description": "The mime type of this content"
},
{
"key": "Date",
"value": "Fri, 21 Sep 2018 13:28:31 GMT",
"name": "Date",
"description": "The date and time that the message was sent"
},
{
"key": "Expect-CT",
"value": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
"name": "Expect-CT",
"description": "Custom header"
},
{
"key": "OData-Version",
"value": "4.0",
"name": "OData-Version",
"description": "Custom header"
},
{
"key": "Request-Context",
"value": "appId=cid-v1:7ebf97e7-ed13-4640-bfa8-136a94cd5294",
"name": "Request-Context",
"description": "Custom header"
},
{
"key": "Server",
"value": "cloudflare",
"name": "Server",
"description": "A name for the server"
},
{
"key": "Set-Cookie",
"value": "; SameSite=lax",
"name": "Set-Cookie",
"description": "an HTTP cookie"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31536000; includeSubDomains",
"name": "Strict-Transport-Security",
"description": "A HSTS Policy informing the HTTP client how long to cache the HTTPS only policy and whether this applies to subdomains."
},
{
"key": "X-Content-Type-Options",
"value": "nosniff",
"name": "X-Content-Type-Options",
"description": "The only defined value, \"nosniff\", prevents Internet Explorer from MIME-sniffing a response away from the declared content-type"
},
{
"key": "X-Frame-Options",
"value": "DENY",
"name": "X-Frame-Options",
"description": "Clickjacking protection: \"deny\" - no rendering within a frame, \"sameorigin\" - no rendering if origin mismatch"
},
{
"key": "api-supported-versions",
"value": "6.0",
"name": "api-supported-versions",
"description": "Custom header"
}
],
"cookie": [
{
"expires": "Invalid Date",
"httpOnly": true,
"domain": "uipath.com",
"path": "/",
"secure": true,
"value": "d3b89a558feb68050f4b847c971f595771513704902",
"key": "__cfduid"
},
{
"expires": "Invalid Date",
"httpOnly": false,
"domain": "beta.uipath.com",
"path": "/api/Account",
"secure": false,
"value": ""
},
{
"expires": "Invalid Date",
"httpOnly": false,
"domain": "beta.uipath.com",
"path": "/odata/Jobs",
"secure": false,
"value": ""
},
{
"expires": "Invalid Date",
"httpOnly": false,
"domain": "beta.uipath.com",
"path": "/odata",
"secure": false,
"value": ""
},
{
"expires": "Invalid Date",
"httpOnly": true,
"domain": "beta.uipath.com",
"path": "/",
"secure": false,
"value": "7257e4e124a8dda60e5509939bf9c2e4e6e40cd21b3b6ea3baa3c44843eef5ff",
"key": "ARRAffinity"
}
],
"body": "{\n \"@odata.context\": \"https://beta.uipath.com/odata/$metadata#Jobs\",\n \"value\": [\n {\n \"Key\": \"b618cdfd-8714-4dbf-9a00-0586a8953c90\",\n \"StartTime\": null,\n \"EndTime\": null,\n \"State\": \"Pending\",\n \"Source\": \"Manual\",\n \"SourceType\": \"Manual\",\n \"BatchExecutionKey\": \"abbbb5de-d46a-4b9b-8f73-8a3247be0a0e\",\n \"Info\": null,\n \"CreationTime\": \"2018-09-21T13:28:31.1449691Z\",\n \"StartingScheduleId\": null,\n \"ReleaseName\": \"Heyyo_playground\",\n \"Type\": \"Unattended\",\n \"InputArguments\": \"{\\\"greeting\\\":\\\"Aloha\\\"}\",\n \"OutputArguments\": null,\n \"Id\": 160856\n }\n ]\n}"
}
]
}