? Representation Formats
All API requests are composed of light-weight JSON delivered as an HTTP POST request to the endpoint URL.
All JSON should be UTF-8 encoded.
Date and time values are of the form YYYY-MM-DD HH:MM:SS.
Booleans are either 1 (true) or 0 (false).
REST API Domain: https://api.divako.no
JSON Format
{
"status": {
"request": "module_name",
"request_unix_time": 1535741699,
"response_status": "ok",
"error_code": 0,
"generation_time": 0.26813411712646484,
"records_total": 10,
"records_response": 15
},
"records": []
}
POST request filtering:
Method | Example | Description |
---|---|---|
Exact value | "attribute": "value" | Select rows where this attribute is exact value |
is not | "attribute**!**": "value" | Select rows where this attribute is not that value |
Empty value | "attribute": "NULL" | Select rows where this attribute is NULL |
Number is bigger then... | "attribute**>**": "value" | Select rows where this attribute is bigger number then that value |
Number is smaller then... | "attribute**<**": "value" | Select rows where this attribute is smaller number then that value |
Find in variable | "attribute": "value %" "attribute": "%value" "attribute": "%value%" |
Select rows if some part on that attribute fits with the value |
? Setting the authentication token
For requests to the RESTful JSON interface, you need to set the Authorization key using the X-Authorization header field. The key needs to be present for each request.
X-Authorization: {API_KEY}
? Sample request in PHP using cURL
<?php
const api_key = 'your-api-key';
const divako_url = 'https://api.divako.no';// Simple HTTP Request function to make REST API requests
function http_request( $method, $url, array $post = [], array $header = [] ): mixed
{
$json = json_encode( $post );
$header = array_merge( [
"Content-Type: application/json",
"Content-Length: " . strlen( $json ) ]
, $header );
$ch = curl_init( divako_url . $url );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $method );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
$str = curl_exec( $ch );
return json_decode( $str, true );
}
// requesting list of categories
$categories = http_request('GET', '/categories', [], [ "X-Authorization: " . api_key ] );// print list of categories
print_r($categories);
? Responses
All responses are wrapped in a top-level response element. The status attribute will let you know whether the request succeeded or failed. Status can be OK or ERROR. In all cases, the API should return an HTTP Status Code that indicates the nature of the failure (below), with a response body in JSON format containing additional information.
? Code Message Description
- 200 Success If data was requested, it will be available in the data field at the top level of the response body.
- 400 Invalid request This usually occurs because of a missing or malformed parameter. Check the documentation and the syntax of your request and try again.
- 401 No authorization A valid API key was not provided with the request, so the API could not associate a user with the request.
- 403 Forbidden The API key was wrong.
- 500 Server error There was a problem on our end.
? API REQUESTS
With REST you can use Divako to parse data direcly in your browser. This is a nice feature if you want to test a device or you have payloads that are not loaded to Divako. Add the payload to the REST-string and get parsed data in JSON in return. We alreay have complete parsers for all wM-Bus and more than 16 different LoRaWan suppliers / producers.