Record Measurements via API
This is a quick tutorial that will show you how you can use the Datacake REST-API to record measurement values into your devices.
There is a large overview of Endpoints and how they function including some examples on an external developer overview. Follow this link if you would like to dive deeply into how the REST-API works.
Datacake API Reference

Record Multiple Values at once

Payload Structure

Make sure that you structure the payload like in the following snippet.
1
[
2
{"field": "WATT", "value": msg.payload.watt },
3
{"field": "AMPERE", "value": msg.payload.ampere},
4
{"field": "VOLT", "value": msg.payload.volt}
5
];
Copied!
So the general structure is:
1
[{"field":"field1", "value":123.00}, {"field":"field2", "value":"a string"}]
Copied!

URL

The URL you should use for recording multiple measurements at once is:
https://api.datacake.co/v1/devices/22h7c45f-2917-358-9db1-d8a544ab78ed/record/?batch=true
It is structured as follow:
https://api.datacake.co/v1/devices/<<device-id>>/record/?batch=true

The Device-Id (<<device-id>>)

This is the ID of your Device. You find this in the URL of the Datacake Portal and on the Device-View.
Device-ID

Rate Limiting

Per default the Datacake REST-API has an internal rate limiting of 1 write per second and per field. If you want to record historical data this might be an issue. So please contact us so that we can deactivate that for you.

Examples

Here you find some Examples that show you how to record multiple measurements.

Curl

1
curl https://api.datacake.co/v1/devices/22h7c45f-2917-358-9db1-d8a544ab78ed/record/?batch=true
2
-X POST
3
-H "Authorization: Token 923847692384769283469823467"
4
-H "Content-Type: application/json"
5
--data '[\
6
{\
7
"field": "TEMPERATURE",\
8
"value": 23.5,\
9
"timestamp": "1555570137"\
10
}\,
11
{\
12
"field": "HUMIDITY",\
13
"value": 42,\
14
"timestamp": "1555570137"\
15
}\
16
]'
Copied!

Javascript

1
// Set device_id to serial-number of Datacake API Device
2
device_id = "be525e29-4398-4fc1-a928-dead7fdfe218";
3
4
// Set Token to your personal access token or individual token
5
token = "put your token in here";
6
7
// This is the API Information for the HTTP Request Node
8
url = "https://api.datacake.co/v1/devices/"+device_id+"/record/?batch=true"
9
10
// Create Header for Node-RED HTTP Node
11
headers = {
12
"Authorization": "Token "+token,
13
"Content-Type": "application/json"
14
};
15
16
// Now we are going to create the Payload we forward to Datacake API
17
payload = [
18
{
19
"field": "WATT",
20
"value": msg.payload.watt
21
},
22
{
23
"field": "AMPERE",
24
"value": msg.payload.ampere
25
},
26
{
27
"field": "VOLT",
28
"value": msg.payload.volt
29
}
30
];
31
32
// Return it - were all set!
33
return msg;
Copied!

Python

1
import requests
2
3
DTCK_KEY = 'yourapikey'
4
DTCK_DEVICE_ID = 'yourdeviceid'
5
6
if __name__ == "__main__":
7
8
power_dc1 = 234
9
power_dc2 = 345
10
11
requests.post(f"https://api.datacake.co/v1/devices/{DTCK_DEVICE_ID}/record/?batch=true", headers={"Authorization": f"Token {DTCK_KEY}"}, json=[
12
{
13
"field": "POWER_DC1",
14
"value": power_dc1,
15
"timestamp": "1555570137" # a timestamp is optional
16
},
17
{
18
"field": "POWER_DC2",
19
"value": power_dc2
20
}
21
])
Copied!
Last modified 10mo ago