Chilkat Online Tools

SQL Server / Orchestrator API Documentation / Restart Process

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

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

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

    -- {
    --   "jobId": 123
    -- }

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'jobId', 123

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-UIPATH-OrganizationUnitId', '{{folderId}}'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-UIPATH-TenantName', '{{tenantName}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.RestartJob', 'application/json', @json
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        RETURN
      END

    DECLARE @sbResponseBody int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @resp

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- {
    --   "@odata.context": "https://cloud.uipath.com/org/tenant/orchestrator_/odata/$metadata#Jobs/$entity",
    --   "Key": "64eb533a-5b10-437f-8a16-c896419f1793",
    --   "StartTime": null,
    --   "EndTime": null,
    --   "State": "Pending",
    --   "JobPriority": "Normal",
    --   "Source": "Manual",
    --   "SourceType": "Manual",
    --   "BatchExecutionKey": "26918b13-2e8f-456f-85e1-f2d6a164427e",
    --   "Info": null,
    --   "CreationTime": "2021-03-31T12:55:07.273Z",
    --   "StartingScheduleId": null,
    --   "ReleaseName": "Add a pet to pet store by queue item",
    --   "Type": "Unattended",
    --   "InputArguments": null,
    --   "OutputArguments": null,
    --   "HostMachineName": null,
    --   "HasMediaRecorded": false,
    --   "PersistenceId": null,
    --   "ResumeVersion": null,
    --   "StopStrategy": null,
    --   "RuntimeType": "Unattended",
    --   "RequiresUserInteraction": true,
    --   "ReleaseVersionId": null,
    --   "EntryPointPath": null,
    --   "OrganizationUnitId": 515128,
    --   "OrganizationUnitFullyQualifiedName": null,
    --   "Reference": "",
    --   "ProcessType": "Process",
    --   "Id": 12764707
    -- }

    -- Sample code for parsing the JSON response...
    -- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    DECLARE @odata_context nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @odata_context OUT, '"@odata.context"'
    DECLARE @Key nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Key OUT, 'Key'
    DECLARE @StartTime nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @StartTime OUT, 'StartTime'
    DECLARE @EndTime nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @EndTime OUT, 'EndTime'
    DECLARE @State nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @State OUT, 'State'
    DECLARE @JobPriority nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @JobPriority OUT, 'JobPriority'
    DECLARE @Source nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Source OUT, 'Source'
    DECLARE @SourceType nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @SourceType OUT, 'SourceType'
    DECLARE @BatchExecutionKey nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @BatchExecutionKey OUT, 'BatchExecutionKey'
    DECLARE @Info nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Info OUT, 'Info'
    DECLARE @CreationTime nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @CreationTime OUT, 'CreationTime'
    DECLARE @StartingScheduleId nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @StartingScheduleId OUT, 'StartingScheduleId'
    DECLARE @ReleaseName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @ReleaseName OUT, 'ReleaseName'
    DECLARE @v_Type nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'Type'
    DECLARE @InputArguments nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @InputArguments OUT, 'InputArguments'
    DECLARE @OutputArguments nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @OutputArguments OUT, 'OutputArguments'
    DECLARE @HostMachineName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @HostMachineName OUT, 'HostMachineName'
    DECLARE @HasMediaRecorded int
    EXEC sp_OAMethod @jResp, 'BoolOf', @HasMediaRecorded OUT, 'HasMediaRecorded'
    DECLARE @PersistenceId nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @PersistenceId OUT, 'PersistenceId'
    DECLARE @ResumeVersion nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @ResumeVersion OUT, 'ResumeVersion'
    DECLARE @StopStrategy nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @StopStrategy OUT, 'StopStrategy'
    DECLARE @RuntimeType nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @RuntimeType OUT, 'RuntimeType'
    DECLARE @RequiresUserInteraction int
    EXEC sp_OAMethod @jResp, 'BoolOf', @RequiresUserInteraction OUT, 'RequiresUserInteraction'
    DECLARE @ReleaseVersionId nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @ReleaseVersionId OUT, 'ReleaseVersionId'
    DECLARE @EntryPointPath nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @EntryPointPath OUT, 'EntryPointPath'
    DECLARE @OrganizationUnitId int
    EXEC sp_OAMethod @jResp, 'IntOf', @OrganizationUnitId OUT, 'OrganizationUnitId'
    DECLARE @OrganizationUnitFullyQualifiedName nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @OrganizationUnitFullyQualifiedName OUT, 'OrganizationUnitFullyQualifiedName'
    DECLARE @Reference nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Reference OUT, 'Reference'
    DECLARE @ProcessType nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @ProcessType OUT, 'ProcessType'
    DECLARE @Id int
    EXEC sp_OAMethod @jResp, 'IntOf', @Id OUT, 'Id'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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 '{
    "jobId": {{lastJobId}}
}'
https://domain.com/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.RestartJob

Postman Collection Item JSON

{
  "name": "Restart Process",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "pm.test(\"Status code is 200\", function () {\r",
          "    pm.response.to.have.status(200);\r",
          "});\r",
          "\r",
          "//set JobId key\r",
          "var myResponse = pm.response.json();\r",
          "pm.collectionVariables.set(\"jobId\", myResponse.Id);\r",
          "console.log(pm.collectionVariables.get(\"jobId\"));\r",
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "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    \"jobId\": {{lastJobId}}\r\n}"
    },
    "url": {
      "raw": "{{url}}/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.RestartJob",
      "host": [
        "{{url}}"
      ],
      "path": [
        "orchestrator_",
        "odata",
        "Jobs",
        "UiPath.Server.Configuration.OData.RestartJob"
      ]
    }
  },
  "response": [
    {
      "name": "Restart Process",
      "originalRequest": {
        "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    \"jobId\": {{lastJobId}}\r\n}"
        },
        "url": {
          "raw": "{{url}}/orchestrator_/odata/Jobs/UiPath.Server.Configuration.OData.RestartJob",
          "host": [
            "{{url}}"
          ],
          "path": [
            "orchestrator_",
            "odata",
            "Jobs",
            "UiPath.Server.Configuration.OData.RestartJob"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Wed, 31 Mar 2021 12:55:07 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json; odata.metadata=minimal; odata.streaming=true"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache, no-store, must-revalidate"
        },
        {
          "key": "Pragma",
          "value": "no-cache"
        },
        {
          "key": "Expires",
          "value": "-1"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Request-Context",
          "value": "appId=cid-v1:04884d99-0742-441b-a23c-847133cb0130"
        },
        {
          "key": "X-Robots-Tag",
          "value": "noindex,nofollow"
        },
        {
          "key": "X-Download-Options",
          "value": "noopen"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-Frame-Options",
          "value": "Deny"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536000; includeSubDomains"
        },
        {
          "key": "Content-Security-Policy",
          "value": "default-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: https://*.blob.core.windows.net https://*.amazonaws.com blob:;font-src 'self' data:;connect-src 'self' wss: https://sentry.io https://studio-feedback.azure-api.net https://storage.googleapis.com https://*.service.signalr.net https://*.blob.core.windows.net https://*.amazonaws.com dc.services.visualstudio.com;worker-src 'self' blob:"
        },
        {
          "key": "X-Correlation-ID",
          "value": "8abd67df-6582-4561-a41f-a96ecce1cd89"
        },
        {
          "key": "OData-Version",
          "value": "4.0"
        },
        {
          "key": "api-supported-versions",
          "value": "12.0"
        },
        {
          "key": "CF-Cache-Status",
          "value": "DYNAMIC"
        },
        {
          "key": "cf-request-id",
          "value": "0929f328050000cba0ef84b000000001"
        },
        {
          "key": "Expect-CT",
          "value": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
        },
        {
          "key": "Server",
          "value": "cloudflare"
        },
        {
          "key": "CF-RAY",
          "value": "6389baecd807cba0-VIE"
        },
        {
          "key": "Content-Encoding",
          "value": "br"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"@odata.context\": \"https://cloud.uipath.com/org/tenant/orchestrator_/odata/$metadata#Jobs/$entity\",\n    \"Key\": \"64eb533a-5b10-437f-8a16-c896419f1793\",\n    \"StartTime\": null,\n    \"EndTime\": null,\n    \"State\": \"Pending\",\n    \"JobPriority\": \"Normal\",\n    \"Source\": \"Manual\",\n    \"SourceType\": \"Manual\",\n    \"BatchExecutionKey\": \"26918b13-2e8f-456f-85e1-f2d6a164427e\",\n    \"Info\": null,\n    \"CreationTime\": \"2021-03-31T12:55:07.273Z\",\n    \"StartingScheduleId\": null,\n    \"ReleaseName\": \"Add a pet to pet store by queue item\",\n    \"Type\": \"Unattended\",\n    \"InputArguments\": null,\n    \"OutputArguments\": null,\n    \"HostMachineName\": null,\n    \"HasMediaRecorded\": false,\n    \"PersistenceId\": null,\n    \"ResumeVersion\": null,\n    \"StopStrategy\": null,\n    \"RuntimeType\": \"Unattended\",\n    \"RequiresUserInteraction\": true,\n    \"ReleaseVersionId\": null,\n    \"EntryPointPath\": null,\n    \"OrganizationUnitId\": 515128,\n    \"OrganizationUnitFullyQualifiedName\": null,\n    \"Reference\": \"\",\n    \"ProcessType\": \"Process\",\n    \"Id\": 12764707\n}"
    }
  ]
}