Chilkat Online Tools

PowerBuilder / Orchestrator / Jobs - Stop Job

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Key
string ls_StartTime
string ls_EndTime
string ls_State
string ls_Source
string ls_SourceType
string ls_BatchExecutionKey
string ls_Info
string ls_CreationTime
string ls_StartingScheduleId
string ls_ReleaseName
string ls_V_Type
string ls_InputArguments
string ls_OutputArguments
integer li_Id
string ls_Odata_context
integer i
integer li_Count_i

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "strategy": "2"
// }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("strategy","2")

loo_Http.SetRequestHeader("Content-Type","application/json")
// Adds the "Authorization: Bearer <access_token>" header.
loo_Http.AuthToken = "<access_token>"
loo_Http.SetRequestHeader("X-UIPATH-OrganizationUnitId","{{folderId}}")
loo_Http.SetRequestHeader("X-UIPATH-TenantName","{{tenantName}}")

loo_Resp = loo_Http.PostJson3("https://domain.com/odata/Jobs(/:jobId)/UiPath.Server.Configuration.OData.StopJob","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_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": "{\"message\":\"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

ls_Odata_context = loo_JResp.StringOf("~"@odata.context~"")
i = 0
li_Count_i = loo_JResp.SizeOfArray("value")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Key = loo_JResp.StringOf("value[i].Key")
    ls_StartTime = loo_JResp.StringOf("value[i].StartTime")
    ls_EndTime = loo_JResp.StringOf("value[i].EndTime")
    ls_State = loo_JResp.StringOf("value[i].State")
    ls_Source = loo_JResp.StringOf("value[i].Source")
    ls_SourceType = loo_JResp.StringOf("value[i].SourceType")
    ls_BatchExecutionKey = loo_JResp.StringOf("value[i].BatchExecutionKey")
    ls_Info = loo_JResp.StringOf("value[i].Info")
    ls_CreationTime = loo_JResp.StringOf("value[i].CreationTime")
    ls_StartingScheduleId = loo_JResp.StringOf("value[i].StartingScheduleId")
    ls_ReleaseName = loo_JResp.StringOf("value[i].ReleaseName")
    ls_V_Type = loo_JResp.StringOf("value[i].Type")
    ls_InputArguments = loo_JResp.StringOf("value[i].InputArguments")
    ls_OutputArguments = loo_JResp.StringOf("value[i].OutputArguments")
    li_Id = loo_JResp.IntOf("value[i].Id")
    i = i + 1
loop


destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_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 '{
	"strategy": "2"
}'
https://domain.com/odata/Jobs(/:jobId)/UiPath.Server.Configuration.OData.StopJob

Postman Collection Item JSON

{
  "name": "Jobs - Stop Job",
  "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": "{\r\n\t\"strategy\": \"2\"\r\n}"
    },
    "url": {
      "raw": "{{url}}/odata/Jobs(/:jobId)/UiPath.Server.Configuration.OData.StopJob",
      "host": [
        "{{url}}"
      ],
      "path": [
        "odata",
        "Jobs(",
        ":jobId)",
        "UiPath.Server.Configuration.OData.StopJob"
      ],
      "variable": [
        {
          "key": "jobId)",
          "value": "",
          "type": "string"
        }
      ]
    },
    "description": "Stops a running job.\n\nThe *jobId* path parameter is retrieved from the **Jobs - Start Job** or **Jobs - Get** calls.\nThe *strategy* body parameter may have a value of either 1 (meaning Soft Stop) or 2 (meaning Kill)."
  },
  "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\": \"5b754c63-5d1a-4c37-bb9b-74b69e4934bf\",\r\n     \"Strategy\": \"Specific\",\r\n     \"RobotIds\": [ 1553 ],\r\n     \"NoOfRobots\": 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"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "",
      "header": [
        {
          "key": "CF-RAY",
          "value": "43b31c105eefbf07-FRA",
          "name": "CF-RAY",
          "description": "",
          "type": "text"
        },
        {
          "key": "Cache-Control",
          "value": "no-store, must-revalidate, no-cache, max-age=0",
          "name": "Cache-Control",
          "description": "",
          "type": "text"
        },
        {
          "key": "Connection",
          "value": "keep-alive",
          "name": "Connection",
          "description": "",
          "type": "text"
        },
        {
          "key": "Content-Length",
          "value": "425",
          "name": "Content-Length",
          "description": "",
          "type": "text"
        },
        {
          "key": "Content-Type",
          "value": "application/json; odata.metadata=minimal",
          "name": "Content-Type",
          "description": "",
          "type": "text"
        },
        {
          "key": "Date",
          "value": "Mon, 16 Sep 2018 08:30:56 GMT",
          "name": "Date",
          "description": "",
          "type": "text"
        },
        {
          "key": "Expect-CT",
          "value": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
          "name": "Expect-CT",
          "description": "",
          "type": "text"
        },
        {
          "key": "OData-Version",
          "value": "4.0",
          "name": "OData-Version",
          "description": "",
          "type": "text"
        },
        {
          "key": "Server",
          "value": "cloudflare",
          "name": "Server",
          "description": "",
          "type": "text"
        },
        {
          "key": "Set-Cookie",
          "value": "; SameSite=lax",
          "name": "Set-Cookie",
          "description": "",
          "type": "text"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536000; includeSubDomains",
          "name": "Strict-Transport-Security",
          "description": "",
          "type": "text"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff",
          "name": "X-Content-Type-Options",
          "description": "",
          "type": "text"
        },
        {
          "key": "X-Frame-Options",
          "value": "DENY",
          "name": "X-Frame-Options",
          "description": "",
          "type": "text"
        },
        {
          "key": "api-supported-versions",
          "value": "5.0",
          "name": "api-supported-versions",
          "description": "",
          "type": "text"
        }
      ],
      "cookie": [
      ],
      "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\": \"{\\\"message\\\":\\\"Aloha\\\"}\",\n            \"OutputArguments\": null,\n            \"Id\": 160856\n        }\n    ]\n}"
    }
  ]
}