Chilkat Online Tools

SQL Server / Orchestrator API Documentation / Start 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.

    -- {
    --   "startInfo": {
    --     "ReleaseKey": "{{releaseKey}}",
    --     "JobsCount": 1,
    --     "JobPriority": "Normal",
    --     "Strategy": "ModernJobsCount",
    --     "RuntimeType": "Unattended",
    --     "InputArguments": "{\"status\":\"Sold\"}"
    --   }
    -- }

    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, 'UpdateString', @success OUT, 'startInfo.ReleaseKey', '{{releaseKey}}'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'startInfo.JobsCount', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'startInfo.JobPriority', 'Normal'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'startInfo.Strategy', 'ModernJobsCount'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'startInfo.RuntimeType', 'Unattended'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'startInfo.InputArguments', '{"status":"Sold"}'

    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}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs', '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",
    --   "value": [
    --     {
    --       "Key": "4d7ea00a-996b-4a7d-961b-9068d9a519b3",
    --       "StartTime": null,
    --       "EndTime": null,
    --       "State": "Pending",
    --       "JobPriority": "Normal",
    --       "Source": "Manual",
    --       "SourceType": "Manual",
    --       "BatchExecutionKey": "1e089817-98da-4dd0-b527-7aea211c4ef9",
    --       "Info": null,
    --       "CreationTime": "2021-04-20T09:06:13.78Z",
    --       "StartingScheduleId": null,
    --       "ReleaseName": "Update existsing pet by ID",
    --       "Type": "Unattended",
    --       "InputArguments": "{\"status\":\"Sold\"}",
    --       "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": 14435785
    --     }
    --   ]
    -- }

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

    DECLARE @Key nvarchar(4000)

    DECLARE @StartTime nvarchar(4000)

    DECLARE @EndTime nvarchar(4000)

    DECLARE @State nvarchar(4000)

    DECLARE @JobPriority nvarchar(4000)

    DECLARE @Source nvarchar(4000)

    DECLARE @SourceType nvarchar(4000)

    DECLARE @BatchExecutionKey nvarchar(4000)

    DECLARE @Info nvarchar(4000)

    DECLARE @CreationTime nvarchar(4000)

    DECLARE @StartingScheduleId nvarchar(4000)

    DECLARE @ReleaseName nvarchar(4000)

    DECLARE @v_Type nvarchar(4000)

    DECLARE @InputArguments nvarchar(4000)

    DECLARE @OutputArguments nvarchar(4000)

    DECLARE @HostMachineName nvarchar(4000)

    DECLARE @HasMediaRecorded int

    DECLARE @PersistenceId nvarchar(4000)

    DECLARE @ResumeVersion nvarchar(4000)

    DECLARE @StopStrategy nvarchar(4000)

    DECLARE @RuntimeType nvarchar(4000)

    DECLARE @RequiresUserInteraction int

    DECLARE @ReleaseVersionId nvarchar(4000)

    DECLARE @EntryPointPath nvarchar(4000)

    DECLARE @OrganizationUnitId int

    DECLARE @OrganizationUnitFullyQualifiedName nvarchar(4000)

    DECLARE @Reference nvarchar(4000)

    DECLARE @ProcessType nvarchar(4000)

    DECLARE @Id int

    DECLARE @odata_context nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @odata_context OUT, '"@odata.context"'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'value'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @Key OUT, 'value[i].Key'
        EXEC sp_OAMethod @jResp, 'StringOf', @StartTime OUT, 'value[i].StartTime'
        EXEC sp_OAMethod @jResp, 'StringOf', @EndTime OUT, 'value[i].EndTime'
        EXEC sp_OAMethod @jResp, 'StringOf', @State OUT, 'value[i].State'
        EXEC sp_OAMethod @jResp, 'StringOf', @JobPriority OUT, 'value[i].JobPriority'
        EXEC sp_OAMethod @jResp, 'StringOf', @Source OUT, 'value[i].Source'
        EXEC sp_OAMethod @jResp, 'StringOf', @SourceType OUT, 'value[i].SourceType'
        EXEC sp_OAMethod @jResp, 'StringOf', @BatchExecutionKey OUT, 'value[i].BatchExecutionKey'
        EXEC sp_OAMethod @jResp, 'StringOf', @Info OUT, 'value[i].Info'
        EXEC sp_OAMethod @jResp, 'StringOf', @CreationTime OUT, 'value[i].CreationTime'
        EXEC sp_OAMethod @jResp, 'StringOf', @StartingScheduleId OUT, 'value[i].StartingScheduleId'
        EXEC sp_OAMethod @jResp, 'StringOf', @ReleaseName OUT, 'value[i].ReleaseName'
        EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'value[i].Type'
        EXEC sp_OAMethod @jResp, 'StringOf', @InputArguments OUT, 'value[i].InputArguments'
        EXEC sp_OAMethod @jResp, 'StringOf', @OutputArguments OUT, 'value[i].OutputArguments'
        EXEC sp_OAMethod @jResp, 'StringOf', @HostMachineName OUT, 'value[i].HostMachineName'
        EXEC sp_OAMethod @jResp, 'BoolOf', @HasMediaRecorded OUT, 'value[i].HasMediaRecorded'
        EXEC sp_OAMethod @jResp, 'StringOf', @PersistenceId OUT, 'value[i].PersistenceId'
        EXEC sp_OAMethod @jResp, 'StringOf', @ResumeVersion OUT, 'value[i].ResumeVersion'
        EXEC sp_OAMethod @jResp, 'StringOf', @StopStrategy OUT, 'value[i].StopStrategy'
        EXEC sp_OAMethod @jResp, 'StringOf', @RuntimeType OUT, 'value[i].RuntimeType'
        EXEC sp_OAMethod @jResp, 'BoolOf', @RequiresUserInteraction OUT, 'value[i].RequiresUserInteraction'
        EXEC sp_OAMethod @jResp, 'StringOf', @ReleaseVersionId OUT, 'value[i].ReleaseVersionId'
        EXEC sp_OAMethod @jResp, 'StringOf', @EntryPointPath OUT, 'value[i].EntryPointPath'
        EXEC sp_OAMethod @jResp, 'IntOf', @OrganizationUnitId OUT, 'value[i].OrganizationUnitId'
        EXEC sp_OAMethod @jResp, 'StringOf', @OrganizationUnitFullyQualifiedName OUT, 'value[i].OrganizationUnitFullyQualifiedName'
        EXEC sp_OAMethod @jResp, 'StringOf', @Reference OUT, 'value[i].Reference'
        EXEC sp_OAMethod @jResp, 'StringOf', @ProcessType OUT, 'value[i].ProcessType'
        EXEC sp_OAMethod @jResp, 'IntOf', @Id OUT, 'value[i].Id'
        SELECT @i = @i + 1
      END

    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-OrganizationUnitId: {{folderId}}"
	-d '{
    "startInfo": {
        "ReleaseKey": "{{releaseKey}}",
        "JobsCount": 1,
        "JobPriority": "Normal",
        "Strategy": "ModernJobsCount",
        "RuntimeType": "Unattended",
        "InputArguments": "{\"status\":\"Sold\"}"
    }
}'
https://domain.com/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs

Postman Collection Item JSON

{
  "name": "Start Process",
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    },
    {
      "listen": "test",
      "script": {
        "exec": [
          "pm.test(\"Status code is 201\", function () {\r",
          "    pm.response.to.have.status(201);\r",
          "});\r",
          "\r",
          "//set JobId key\r",
          "var myResponse = pm.response.json();\r",
          "pm.collectionVariables.set(\"jobId\", myResponse.value[0].Id);\r",
          "console.log(pm.collectionVariables.get(\"jobId\"));"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json",
        "type": "text"
      },
      {
        "key": "X-UIPATH-OrganizationUnitId",
        "value": "{{folderId}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\r\n    \"startInfo\": {\r\n        \"ReleaseKey\": \"{{releaseKey}}\",\r\n        \"JobsCount\": 1,\r\n        \"JobPriority\": \"Normal\",\r\n        \"Strategy\": \"ModernJobsCount\",\r\n        \"RuntimeType\": \"Unattended\",\r\n        \"InputArguments\": \"{\\\"status\\\":\\\"Sold\\\"}\"\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** you need to hand over at least the following request body input parameters:\n\n1. `ReleaseKey`: The ID you get in the previous step _GET Releases by name_. The Orchestator needs this key to run a specific version of a process.\n2. `Strategy`: For modern folders we recommend to make use of _ModernJobsCount_.\n3. `JobsCount`: How often the job will be executed.\n4. `InputArguments`: If your job has input parameters, they can be sent as a JSON string in the _InputArguments_ field. If it does not, this field will be ignored. See how input arguments are handed over in this example.\n\nFind more details on how to start of job [here](https://docs.uipath.com/orchestrator/docs/managing-jobs)."
  },
  "response": [
    {
      "name": "Start Process",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json",
            "type": "text"
          },
          {
            "key": "X-UIPATH-OrganizationUnitId",
            "value": "{{folderId}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\r\n    \"startInfo\": {\r\n        \"ReleaseKey\": \"{{releaseKey}}\",\r\n        \"JobsCount\": 1,\r\n        \"JobPriority\": \"Normal\",\r\n        \"Strategy\": \"ModernJobsCount\",\r\n        \"RuntimeType\": \"Unattended\",\r\n        \"InputArguments\": \"{\\\"status\\\":\\\"Sold\\\"}\"\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": "Date",
          "value": "Tue, 20 Apr 2021 09:06:13 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": "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": "9dca99ab-1885-4420-830c-e3490ae41aad"
        },
        {
          "key": "OData-Version",
          "value": "4.0"
        },
        {
          "key": "api-supported-versions",
          "value": "12.0"
        },
        {
          "key": "CF-Cache-Status",
          "value": "DYNAMIC"
        },
        {
          "key": "cf-request-id",
          "value": "099020c99a00000fae930af000000001"
        },
        {
          "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": "642d37228be00fae-VIE"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"@odata.context\": \"https://cloud.uipath.com/org/tenant/orchestrator_/odata/$metadata#Jobs\",\n    \"value\": [\n        {\n            \"Key\": \"4d7ea00a-996b-4a7d-961b-9068d9a519b3\",\n            \"StartTime\": null,\n            \"EndTime\": null,\n            \"State\": \"Pending\",\n            \"JobPriority\": \"Normal\",\n            \"Source\": \"Manual\",\n            \"SourceType\": \"Manual\",\n            \"BatchExecutionKey\": \"1e089817-98da-4dd0-b527-7aea211c4ef9\",\n            \"Info\": null,\n            \"CreationTime\": \"2021-04-20T09:06:13.78Z\",\n            \"StartingScheduleId\": null,\n            \"ReleaseName\": \"Update existsing pet by ID\",\n            \"Type\": \"Unattended\",\n            \"InputArguments\": \"{\\\"status\\\":\\\"Sold\\\"}\",\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\": 14435785\n        }\n    ]\n}"
    }
  ]
}