Scheduling
SmartApps may schedule future executions using the Schedules API.
Two types of scheduled executions are supported:
- Once schedules are created to be executed exactly once at the specified day and time.
- Cron schedules are created according to a Cron expression. These expressions may define recurring schedules (e.g., execute every fifteen minutes).
#
Creating Scheduled ExecutionsSmartApps do not require any OAuth2 scopes to create schedules.
note
When using a personal access token to read/write schedules, you must include the w:schedules
scope.
An example response to the INITIALIZE phase of the CONFIGURE lifecycle:
#
Once SchedulesOnce schedules are defined in the number of milliseconds from 1 January 1970 UTC (Unix Time).
The request body for Once schedules looks like this:
Here is an example request to create a Once schedule:
- CuRL
- Node
#
Cron SchedulesCron schedules use the Quartz Scheduler format, with an important difference: The seconds field is not supported, and is omitted from the cron expression.
All Cron schedules will be assigned a random seconds field by the SmartThings Platform.
The request body for Cron schedules looks like this:
An example request to create a Cron schedule:
- CuRL
- Node
#
Cron Expression ExamplesExpression | Description |
---|---|
"0/5 * * * ? *" | Fire every five minutes, every day. |
"30 10 * * ? *" | Fire every day at 10:30 a.m. |
"0/10 9 * * ?" | Fire every ten minutes starting at 9 a.m and ending at 9:50 a.m., every day. |
#
TimezonesWhen creating schedules, consider in what time zone the schedule should be executed in. Usually, this will be the time zone of the installed app. You can get the time zone for the Location that the installed app belongs to by using the Locations API.
#
Scheduled execution eventsWhen a scheduled execution is triggered by SmartThings, your app is called with an EVENT lifecycle phase payload. It will contain information about the schedule that triggered the execution:
#
Getting SchedulesSmartApps do not require any OAuth2 scopes to get schedules.
note
When using a personal access token to read/write schedules, you must include the w:schedules
scope.
A sample response to the INITIALIZE phase of the CONFIGURE lifecycle:
#
Get a ScheduleA specific schedule for an installed app can be retrieved by issuing a GET request to /installedapps/{installedAppId}/schedules/{scheduleName}
- CuRL
- Node
A schedule will be returned:
#
Get All SchedulesAll schedules for an installed app can be retrieved by issuing a GET request to /installedapps/{installedAppId}/schedules
:
- CuRL
- Node
A paged result of schedules will be returned:
#
Deleting schedulesnote
All schedules and subscriptions for an installed app are automatically deleted when a user uninstalls an app.
SmartApps do not require any OAuth2 scopes to delete schedules.
note
When using a personal access token to read/write schedules, you must include the w:schedules
scope.
A sample response to the INITIALIZE phase of the CONFIGURE lifecycle:
#
Delete a scheduleIndividual schedules can be deleted for an installed app by issuing a DELETE request to /installedapps/{installedAppId}/schedules/{scheduleName}
:
- CuRL
- Node
#
Delete All SchedulesAll schedules for an installed app can be deleted by issuing a DELETE request to /installedapps/{installedAppId}/schedules
:
- CuRL
- Node
#
Scheduling LimitsEach installed app is limited to having ten pending scheduled executions at any time.
Requests to create any additional pending scheduled executions will result in a 422 Unprocessable Entity
response.