Switch information¶
A switch reports an on/off state and can be asked to change state remotely with POST /request/switch/state. See API usage information for authentication and the response envelope.
Add switch¶
/add/switchCreates a new switch for the logged-in user and returns its id and token.
Request¶
Auth: api_key (query param or cookie) · Content-type: application/x-www-form-urlencoded
Request body:
Send the fields as form data.
| Field name | Description | Type |
|---|---|---|
switch_name |
Name of the switch | str |
switch_type |
Free-text switch type, e.g. Relay |
str |
update_period |
Expected seconds between updates; used to decide Online/Offline |
int |
switch_token |
[Optional] Token used to authenticate updates. Generated when omitted | str |
switch_state |
[Optional] Initial state. Default false |
bool |
switch_status |
[Optional] Initial status. Default Offline |
str |
switch_details |
[Optional] JSON string stored with the switch. Default {} |
json |
last_modified |
[Optional] Initial last-update time (epoch seconds). Default: now | int |
Request example:
https://spoilerinterface.com/interface/add/switch?api_key=3b9e1f0c7a5d4e2f8a6b0c1d
Form data:
Response¶
{
"success": {
"switch_id": 151659085216623,
"switch_token": "9f2c4e7a1b3d5f60718293a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2"
}
}
Field description¶
| Field name | Description | Type |
|---|---|---|
switch_id |
Generated switch id. Use it with the token to push updates | int |
switch_token |
The supplied token, or a generated 100-character hex token | str |
Fails with Maximum number of devices reached. Please upgrade your account. when the account's device limit is reached.
Switch count¶
/switch/countReturns the number of switches owned by the user.
Request¶
Auth: api_key (query param or cookie)
Request body:
None
Request example:
https://spoilerinterface.com/interface/switch/count?api_key=3b9e1f0c7a5d4e2f8a6b0c1d
Response¶
List switches¶
/switch/listLists every switch owned by the user, with its token and current status.
Request¶
Auth: api_key (query param or cookie)
Request body:
None
Request example:
https://spoilerinterface.com/interface/switch/list?api_key=3b9e1f0c7a5d4e2f8a6b0c1d
Response¶
{
"success": [
{
"switch_id": 151659085216623,
"switch_name": "Pump relay",
"switch_type": "Relay",
"update_time": 1763025300,
"switch_status": "Online",
"switch_state": true,
"switch_token": "9f2c4e7a1b3d5f60718293a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2",
"update_period": 120,
"last_modified": 1763025300,
"notification_enabled": true,
"alarms": [],
"switch_details": "{}",
"whatsapp_enabled": false,
"sms_enabled": false,
"requested_state": false,
"requested_state_time": 1763025200,
"notification_users": []
}
]
}
Field description¶
| Field name | Description | Type |
|---|---|---|
switch_id |
Switch id | int |
switch_name |
Switch name | str |
switch_type |
Switch type | str |
update_time |
Same value as last_modified |
int |
switch_status |
Online or Offline |
str |
switch_state |
Last reported state | bool |
switch_token |
Switch token | str |
update_period |
Expected seconds between updates. The device is reported Offline when no update arrives within this period |
int |
last_modified |
Epoch time (seconds) of the last update, shifted by the account's time_offset (minutes) |
int |
notification_enabled |
Email status notifications enabled. null in the database is reported as true by /status and /list |
bool |
alarms |
Alarms configured for the device | arr |
switch_details |
Details JSON as stored | json |
whatsapp_enabled |
WhatsApp notifications enabled (may be null) |
bool |
sms_enabled |
SMS notifications enabled (may be null) |
bool |
requested_state |
State last requested through /request/switch/state (null if never requested) |
bool |
requested_state_time |
When the state was requested (epoch seconds, shifted by time_offset) |
int |
notification_users |
Extra notification recipients (see /edit) |
arr |
switch_status is recalculated on every request: Online when the last update is within update_period seconds, otherwise Offline.
Switch status¶
/switch/statusReturns the current status of a single switch. Authenticated with the device id and token.
Request¶
Auth: Device id + token (no api_key) · Content-type: application/json (only when sending a JSON body)
Request body:
Send as query parameters or a JSON body.
| Field name | Description | Type |
|---|---|---|
switch_id |
Switch id | int |
switch_token |
Switch token | str |
Request example:
Params:
https://spoilerinterface.com/interface/switch/status?switch_id=151659085216623&switch_token=9f2c4e7a1b3d5f60718293a4
JSON body:
Response¶
{
"success": {
"switch_id": 151659085216623,
"switch_status": "Online",
"switch_state": true,
"last_modified": 1763025300,
"update_period": 120,
"notification_enabled": true,
"switch_details": "{}",
"requested_state": false,
"requested_state_time": 1763025200,
"alarms": [],
"notification_users": null
}
}
Field description¶
| Field name | Description | Type |
|---|---|---|
switch_id |
Switch id | int |
switch_status |
Online or Offline |
str |
switch_state |
Last reported state | bool |
last_modified |
Epoch time (seconds) of the last update, shifted by the account's time_offset (minutes) |
int |
update_period |
Expected seconds between updates. The device is reported Offline when no update arrives within this period |
int |
notification_enabled |
Email status notifications enabled. null in the database is reported as true by /status and /list |
bool |
switch_details |
Details JSON as stored | json |
requested_state |
State last requested through /request/switch/state (null if never requested) |
bool |
requested_state_time |
When the state was requested (epoch seconds, shifted by time_offset) |
int |
alarms |
Alarms configured for the device | arr |
notification_users |
Extra notification recipients (see /edit) |
arr |
Update switch¶
/update/switchPushes the current switch state. The response tells the device which state was last requested.
Request¶
Auth: Device id + token (no api_key) · Content-type: application/json (only when sending a JSON body)
Request body:
Send as query parameters or a JSON body (query parameters win when both are present).
| Field name | Description | Type |
|---|---|---|
switch_id |
Switch id | int |
switch_token |
Switch token | str |
switch_state |
Current state (true/false; query parameters also accept 1/0) |
bool |
switch_details |
[Optional] JSON object as a string. Default {}. Stored in the history record only |
json |
epoch_time |
[Optional] Measurement time (epoch seconds). Default: server time. Stored as last_modified |
int |
Request example:
Params:
https://spoilerinterface.com/interface/update/switch?switch_id=151659085216623&switch_token=9f2c4e7a1b3d5f60718293a4&switch_state=true
JSON body:
{
"switch_id": 151659085216623,
"switch_token": "9f2c4e7a1b3d5f60718293a4",
"switch_state": true,
"epoch_time": 1763025300
}
Response¶
Field description¶
| Field name | Description | Type |
|---|---|---|
requested_state |
State requested by the user (null if never requested). The device should switch to it |
bool |
requested_state_time |
When it was requested (epoch seconds, not shifted by time_offset) |
int |
Updates are rate limited by the owner's account type (account type 1 or unset: 59 s, types 2-4: 30 s, type 5 and above: 1 s between updates, measured against the previous last_modified). A blocked update returns HTTP 400:
{
"failed": {
"message": "Please wait for the update period to lapse. Remaining time is: 21",
"remaining_time_sec": 21
}
}
Request switch state¶
/request/switch/stateAsks the switch to change state. The request is stored on the switch and returned to the device on its next /update/switch call.
Request¶
Auth: Device id + token (no api_key) · Content-type: application/json (only when sending a JSON body)
Request body:
Send as query parameters or a JSON body.
| Field name | Description | Type |
|---|---|---|
switch_id |
Switch id | int |
switch_token |
Switch token | str |
switch_request |
Requested state as a string: true, false, 1 or 0 (case-insensitive) |
str |
Request example:
Params:
https://spoilerinterface.com/interface/request/switch/state?switch_id=151659085216623&switch_token=9f2c4e7a1b3d5f60718293a4&switch_request=true
JSON body:
{
"switch_id": 151659085216623,
"switch_token": "9f2c4e7a1b3d5f60718293a4",
"switch_request": "true"
}
Response¶
Any other switch_request value fails with Value not boolean. The request is logged in the notification history (Requested change state to :True).
Switch history¶
/switch/historyReturns the recorded history of the user's switches, oldest record first.
Request¶
Auth: api_key (query param or cookie) · Content-type: application/json
Request body:
Send the filters as a JSON body. A body is required, even if it is only {} (without one the request fails). limit and offset may also be sent as query parameters, but min_epoch_tm_sec, max_epoch_tm_sec and device_id are only read from the JSON body.
| Field name | Description | Type |
|---|---|---|
min_epoch_tm_sec |
[Optional] Start of the window (epoch seconds). Default: now minus 2 days (172800 s) | float |
max_epoch_tm_sec |
[Optional] End of the window (epoch seconds). Default: now | float |
device_id |
[Optional] Return only this switch (must belong to the user, otherwise Invalid device_id). Default: all of the user's switches |
int |
limit |
[Optional] Maximum records per device. Default and maximum: 20000 | int |
offset |
[Optional] Records to skip per device (for paging). Default: 0 | int |
Request example:
https://spoilerinterface.com/interface/switch/history?api_key=3b9e1f0c7a5d4e2f8a6b0c1d
JSON body:
{
"min_epoch_tm_sec": 1762992000,
"max_epoch_tm_sec": 1763078400,
"device_id": 151659085216623,
"limit": 1000,
"offset": 0
}
Response¶
{
"success": [
{
"switch_id": 151659085216623,
"switch_name": "Pump relay",
"switch_type": "Relay",
"min_time": 1700000000,
"max_time": 1763025300,
"data": [
{
"switch_state": true,
"update_time": "2026-11-13T09:15:00"
}
]
}
]
}
Field description¶
| Field name | Description | Type |
|---|---|---|
switch_id |
Switch id | int |
switch_name |
Switch name | str |
switch_type |
Switch type | str |
min_time |
Earliest last_modified across all of the user's history records of this type (not only the requested window), plus the account's time_offset |
int |
max_time |
Latest last_modified across all of the user's history records of this type, plus the account's time_offset |
int |
data |
History records in the requested window | arr |
has_more |
Present (true) only when the device returned 20000 records; request the next page with offset |
bool |
Each data item:
| Field name | Description | Type |
|---|---|---|
switch_state |
Recorded state | bool |
update_time |
Record time as an ISO date-time string, shifted by the account's time_offset |
str |
Edit switch¶
/edit/switchChanges the name, token, update period or notification recipients of a switch owned by the user.
Request¶
Auth: api_key (query param or cookie) · Content-type: application/json (only when sending a JSON body)
Request body:
Send as query parameters or a JSON body (query parameters win).
| Field name | Description | Type |
|---|---|---|
switch_id |
Switch id (must belong to the user) | int |
switch_name |
New name | str |
switch_token |
New token. Devices must use the new token afterwards | str |
update_period |
New update period (seconds) | int |
notification_users |
[Optional] JSON string holding an array of extra notification recipients. Each item: email (required), name, status_alerts, threshold_alerts, sms_alerts, whatsapp_alerts (booleans) and mobile_number (required, + and country code, when sms_alerts or whatsapp_alerts is true). Omit it to keep the current list |
json |
When the request has no JSON body, switch_name, switch_token and update_period must all be sent as query parameters, otherwise it fails with Missing field: .... Inside a JSON body a missing field leaves the current value unchanged.
Request example:
https://spoilerinterface.com/interface/edit/switch?api_key=3b9e1f0c7a5d4e2f8a6b0c1d
JSON body:
{
"switch_id": 151659085216623,
"switch_name": "Pump relay",
"switch_token": "9f2c4e7a1b3d5f60718293a4",
"update_period": 120
}
Response¶
Fails with Not allowed... when the device belongs to another user, and with Validation error in notification_users: ... when notification_users is invalid.
Delete switch¶
/delete/switchDeletes a switch and all of its history records.
Request¶
Auth: api_key (query param or cookie) · Content-type: application/x-www-form-urlencoded
Request body:
Send the fields as form data.
| Field name | Description | Type |
|---|---|---|
switch_id |
Switch id | int |
switch_token |
Switch token | str |
Request example:
https://spoilerinterface.com/interface/delete/switch?api_key=3b9e1f0c7a5d4e2f8a6b0c1d
Form data:
Response¶
Only the owner can delete a device (Not allowed otherwise).
Notification settings¶
/notifications/{device_type}/{alert_type}/{action}Enables or disables email, WhatsApp or SMS notifications for one switch. Replaces the old per-type enable/disable endpoints.
Request¶
Auth: api_key (query param or cookie) and device id + token · Content-type: application/json (only when sending a JSON body)
Request body:
device_type is switch. alert_type is alerts (email status notifications, notification_enabled), whatsapp (whatsapp_enabled) or sms (sms_enabled). action is enable or disable.
Send the device credentials as query parameters or a JSON body.
| Field name | Description | Type |
|---|---|---|
device_id |
Switch id | int |
device_token |
Switch token | str |
URLs for this device type:
https://spoilerinterface.com/interface/notifications/switch/alerts/enablehttps://spoilerinterface.com/interface/notifications/switch/alerts/disablehttps://spoilerinterface.com/interface/notifications/switch/whatsapp/enablehttps://spoilerinterface.com/interface/notifications/switch/whatsapp/disablehttps://spoilerinterface.com/interface/notifications/switch/sms/enablehttps://spoilerinterface.com/interface/notifications/switch/sms/disable
Request example:
https://spoilerinterface.com/interface/notifications/switch/alerts/disable?api_key=3b9e1f0c7a5d4e2f8a6b0c1d&device_id=151659085216623&device_token=9f2c4e7a1b3d5f60718293a4
JSON body (with ?api_key= in the URL or the cookie):
Response¶
The change is logged in the notification history (e.g. Notifications disabled). See Notifications for details and error messages.