Skip to main content

Error handling

When you perform an invalid request or something went wrong, the API will respond with an error message. You have to check if the HTTP status code returns 200 OK before parsing the result. If you use an endpoint that returns JSON, you also will receive an object with some error information.

Error codes

The predefined error codes are as follows:

CodeDescription
2BODY_CONTAINS_INVALID_JSON
7INVALID_VALUE_FOR_PARAMETER
8PARAMETER_IS_NOT_MODIFIABLE
201REQUEST_TO_LONG
202API_DISABLED
901INTERNAL_ERROR

Examples

API was disabled

<Request>
GET http://{IP address}/api/v1/data

<Response>
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: <length>

{
"error": {
"id": 202,
"description": "API not enabled"
}
}

Invalid JSON

<Request>
PUT http://{IP address}/api/v1/state HTTP/1.1
Content-Type: application/json
Content-Length: <length>
{
"power_on": invalid_value
}

<Response>
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: <length>

{
"error": {
"id": 2,
"description": "Body contains invalid json"
}
}

Invalid value

<Request>
PUT http://{IP address}/api/v1/state HTTP/1.1
Content-Type: application/json
Content-Length: <length>
{
"brightness": 500
}

<Response>
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: <length>

{
"error": {
"id": 7,
"description": "brightness value limited to 0-255"
}
}

Turn off socket when switch-lock is enabled

<Request>
PUT http://{IP address}/api/v1/state HTTP/1.1
Content-Type: application/json
Content-Length: <length>
{
"power_on": false
}

<Response>
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: <length>

{
"error": {
"id": 8,
"description": "power_on cannot be turned off when switch_lock is on"
}
}