Triggering a schedule

A schedule can be triggered to execute using the REST API.

In the following example, the REST API is used to first find, then trigger, and finally poll to get the results from a schedule. This is somewhat technical and to follow along you will need some experience with HTTP, JSON, and command-line environments.

In this example, we’ll use a Controller installed on the local computer (localhost), port 9000, and assume that a schedule called test has already been created.

Note: The REST API can be explored using real-time calls by going to this URL in a browser: http://{controllerMachine}:{controllerPort}/api/v3

Example: http://myLeapworkController.dom:9001/api/v3

Step 1: Open a command-line environment, such as PowerShell in Windows, Terminal in OSX or Bash in Linux.

Step 2: On the command line, make an HTTP request to the controller to get all schedules on the Controller.

Using curl:

curl -X GET --header 'Accept: application/json' --header 'AccessKey: bTyGAd0UGL70JFQg' 'http://localhost:9001/api/v3/schedules?api_key=bTyGAd0UGL70JFQg' 

Using PowerShell:

$headers = @{}
$headers.Add("AccessKey"," bTyGAd0UGL70JFQg")
Invoke-WebRequest -Uri "http://localhost:9001/api/v3/schedules" -ContentType "application/json" -Headers $headers -Method GET 

If you have performed the HTTP request correctly, the response code will be 200 and the response body will be a JSON string that looks similar to this:

[{
       "$id": "1",
       "IsEnabled": true,
       "DailyWindowPeriodEnd": "23:59:59",
       "LastRunTime": "2018-10-09T09:02:11+00:00",
       "DateCreation": {
              "$id": "2",
              "Value": "2018-10-03T13:48:10.0833124+00:00",
              "LocalDateTime": "2018-10-03T15:48:10.0833124",
              "UtcDateTime": "2018-10-03T13:48:10.0833124",
              "Ticks": 636741712900833200
       },
       "DateModify": {
              "$id": "3",
              "Value": "2018-10-03T13:48:10.0833124+00:00",
              "LocalDateTime": "2018-10-03T15:48:10.0833124",
              "UtcDateTime": "2018-10-03T13:48:10.0833124",
              "Ticks": 636741712900833200
       },
       "Title": "UAT",
       "Type": "ScheduleInfo",
       "Id": "4c369cea-a10d-4c33-8db5-f0f5a7977218"
}]

 Step 3: Identify the Id of the schedule.

The JSON contains a lot of information about the schedule. However, in this example, all we need is the Id, which is 4c369cea-a10d-4c33-8db5-f0f5a7977218

Step 4: Make an HTTP request to run the schedule now.

Using curl:

curl -X PUT --header 'Accept: application/json' --header 'accessKey: bTyGAd0UGL70JFQg' 'http://localhost:9001/api/v3/schedules/4c369cea-a10d-4c33-8db5-f0f5a7977218/runNow'

Using PowerShell:

$headers = @{}
$headers.Add("AccessKey","bTyGAd0UGL70JFQg")
$ScheduleID="4c369cea-a10d-4c33-8db5-f0f5a7977218"
Invoke-WebRequest -Uri "http://localhost:9001/api/v3/schedules/$ScheduleID/runNow" -ContentType "application/json" -Headers $headers -Method PUT 

The response code should be 200 and if you open Studio and look under Scheduling, the schedule should already be queued for execution.

Read more about how to integrate LEAPWORK with third-party systems and learn how to use the results of a scheduled run in a real-life scenario.