Use this endpoint to send data to one or more variables of a Device
To send data to one or more variables of a Device, make a POST request to the following URL:
| HTTP Method | URL |
|---|---|
| POST | https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/ |
Where <device_label> is the label of the Device that receives the data.
Headers
The "X-Auth-Token" and "Content-Type" headers are required in your request:
| Header | Value | Required? | Description |
|---|---|---|---|
X-Auth-Token | Token | Yes | Authentication Token of your account. |
Content-Type | application/json | Yes | The media type of the request body. |
Body
Send an object that contains variable labels as keys and Dots as values. The following payloads are valid:
{
"temperature": 10,
"humidity": 90,
"pressure": 78
}{
"temperature": {
"value": 10,
"timestamp": 1634311791000,
"context": {
"status": "cold"
}
},
"humidity": {
"value": 90,
"timestamp": 1634311791000,
"context": {
"status": "High humidity"
}
},
"pressure": {
"value": 78,
"timestamp": 1634311791000,
"context": {
"status": "Normal"
}
}
}{
"position": {
"value": 1,
"context": {
"lat": "6.5423",
"lng": "-70.5783"
}
}
}{
"temperature": [{
"value": 10,
"timestamp": 1702933911000
},
{
"value": 12,
"timestamp": 1702933912000
}]
}For a detailed explanation of a Dot's keys, see How Ubidots works.
timestampandcontextThe
timestampandcontextparameters are optional.
Maximum lengthThe maximum character length for the body is 10 KB.
Query Parameters
You may add optional parameters to the URL of your request:
| Parameter | Type | Description |
|---|---|---|
| timestamp | Integer | Optional. Timestamp in milliseconds in POSIX format. When present, this timestamp is applied to all Dots in the body unless a local timestamp is sent. |
| token | String | Optional. Token used to authenticate the request. Sending it as a query parameter is supported, but we strongly recommend using the X-Auth-Token header. |
| type | String | Optional. Device type label to apply to the Device if the Device doesn't exist yet. Learn more. |
| status | Boolean | Optional. When set to true, an additional _status object appears in the response. This object contains the IDs of the device and variables, as well as a new field indicating whether each resource was just created. Example:\ |
Sending location data
You can use the context key to send location data. Ubidots automatically recognizes location data when you use these variable labels:
positionlocationgps
There are three ways to send location data:
{
"position": {
"value": 1,
"context": {
"lat": "6.5423",
"lng": "-70.5783"
}
}
}// Because the "value" of a Dot is required, this option sets the variable value to "1".
{
"position": {
"lat": "6.5423",
"lng": "-70.5783"
}
}// Because the "value" of a Dot is required, this option sets the variable value to "1".
{
"position": {
"latitude": "6.5423",
"longitude": "-70.5783"
}
}
Location modesThe location of a Device can be determined by a variable or a fixed property. See Device Location modes to learn more.
Examples
Send a value to a single variable:
Update a variable and let Ubidots apply a timestamp equal to the reception time:
$ curl -X POST 'https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/' \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
-d '{"temperature": 10}'{
"temperature":[{"status_code":201}]
}{
"code":400001,
"message":"The payload sent is not a valid json document."
}{
"code":401001,
"message":"Authentication credentials were not provided."
}Send a value to multiple variables:
Update two variables and let Ubidots apply a timestamp equal to the reception time:
$ curl -X POST 'https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/' \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
-d '{"temperature": 10, "humidity": 90}'{
"temperature":[{"status_code":201}],
"humidity":[{"status_code":201}]
}{
"code":400001,
"message":"The payload sent is not a valid json document."
}{
"code":401001,
"message":"Authentication credentials were not provided."
}Send Dots to multiple variables:
Update multiple variables, including context and timestamp:
$ curl -X POST 'https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/' \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
-d '{
"temperature": {
"value": 10,
"timestamp": 1634311791000,
"context": {
"status": "cold"
}
},
"humidity": {
"value": 90,
"timestamp": 1634311791000,
"context": {
"status": "High humidity"
}
},
"pressure": {
"value": 78,
"timestamp": 1634311791000,
"context": {
"status": "Normal"
}
}
}'{
"temperature":[{"status_code":201}],
"humidity":[{"status_code":201}],
"pressure":[{"status_code":201}]
}{
"code":400001,
"message":"The payload sent is not a valid json document."
}{
"code":401001,
"message":"Authentication credentials were not provided."
}Send location data:
Update a position variable so that the Device displays its location:
curl -X POST 'https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/' \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
-d '{"position":{"lat":6.2442, "lng":-75.5812}}'{
"position":[{"status_code":201}],
}{
"code":400001,
"message":"The payload sent is not a valid json document."
}{
"code":401001,
"message":"Authentication credentials were not provided."
}Send data with global timestamp:
Update multiple variables with a global timestamp sent as a query parameter. Variables with an individual timestamp will override the global timestamp:
$ curl -X POST 'https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/?timestamp=1634311791000' \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
-d '{
"temperature": {
"value": 10,
"context": {
"status": "cold"
}
},
"humidity": {
"value": 90,
"context": {
"status": "High humidity"
}
},
"pressure": {
"value": 78,
"timestamp": 1634336087000,
"context": {
"status": "Normal"
}
}
}'Send historical data to a Device (data logger):
Send multiple Dots per variable. Each Dot requires its own timestamp.
$ curl -X POST 'https://industrial.api.ubidots.com/api/v1.6/devices/<device_label>/' \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
-d '{
"temperature": [
{"value": 10,"timestamp": 1634336087000},
{"value": 11,"timestamp": 1634336088765}
],
"humidity": [
{"value": 90,"timestamp": 1634336087000},
{"value": 95,"timestamp": 1634336088765}
],
"pressure": [
{"value": 78,"timestamp": 1634336087000},
{"value": 82,"timestamp": 1634336088765}
]
}'
