This endpoint computes aggregate statistics for one or more Variables over a time range.
Request
To compute aggregate statistics for one or more Variables, make a POST request to the following URL:
| HTTP Method | URL |
|---|---|
| POST | https://industrial.api.ubidots.com/api/v2.0/data/statistics/ |
Body Parameters
| Parameter | Type | Required? | Description |
|---|---|---|---|
| start | Integer | Yes | Start of the time range as a timestamp in milliseconds (epoch) |
| end | Integer | Yes | End of the time range as a timestamp in milliseconds (epoch). Must be greater than or equal to start |
| decimalPlaces | Integer | No | Number of decimal places for values (0–16). Defaults to the account setting |
| variables | Object Array | Yes | List of variable references to query. Minimum 1 item. See Variables Array |
| aggregations | String Array | No | Which statistics to compute. Defaults to all 11 types. See Aggregation Types below |
Aggregation Types
Each aggregation computes a statistic over the data points in the requested time range. If the aggregations field is omitted, all 11 types are returned.
Aggregations that identify a specific data point (first, last, min, max) include a timestamp alongside the value. All others return only a value.
| Aggregation | Description |
|---|---|
| first | First value in range (with timestamp) |
| last | Last value in range (with timestamp) |
| min | Minimum value (with timestamp) |
| max | Maximum value (with timestamp) |
| count | Number of data points |
| sum | Sum of values |
| mean | Average |
| std | Standard deviation |
| p25 | 25th percentile (approximate) |
| p50 | Median (approximate) |
| p75 | 75th percentile (approximate) |
Header
| Parameter | Required? | Description |
|---|---|---|
| X-Auth-Token | Yes | Authentication Token of account |
$ curl -X POST 'https://industrial.api.ubidots.com/api/v2.0/data/statistics/' \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
-d '{
"start": 1705276800000,
"end": 1705363200000,
"decimalPlaces": 6,
"variables": [
{
"variable": "64b1c0737e206e0f0426475c"
},
{
"variable": "~temperature",
"device": "~my-sensor"
}
],
"aggregations": ["mean", "min", "max", "count"]
}'{
"start": 1705276800000,
"end": 1705363200000,
"results": [
{
"device": {
"url": "https://industrial.api.ubidots.com/api/v2.0/devices/64a1b2c3d4e5f6a7b8c9d0e1/",
"id": "64a1b2c3d4e5f6a7b8c9d0e1",
"label": "my-sensor",
"name": "My Sensor",
"createdAt": "2024-01-15T10:30:00.123456Z"
},
"variable": {
"url": "https://industrial.api.ubidots.com/api/v2.0/variables/64b1c0737e206e0f0426475c/",
"id": "64b1c0737e206e0f0426475c",
"label": "temperature",
"name": "Temperature",
"createdAt": "2024-01-15T10:30:00.123456Z"
},
"results": {
"count": {"value": 100.0},
"mean": {"value": 25.5},
"min": {"value": 15.0, "timestamp": 1705300000000},
"max": {"value": 35.0, "timestamp": 1705350000000}
},
"code": 200
}
]
}{
"start": 1705276800000,
"end": 1705363200000,
"results": [
{
"device": {
"url": "https://industrial.api.ubidots.com/api/v2.0/devices/64a1b2c3d4e5f6a7b8c9d0e1/",
"id": "64a1b2c3d4e5f6a7b8c9d0e1",
"label": "my-sensor",
"name": "My Sensor",
"createdAt": "2024-01-15T10:30:00.123456Z"
},
"variable": {
"url": "https://industrial.api.ubidots.com/api/v2.0/variables/64b1c0737e206e0f0426475c/",
"id": "64b1c0737e206e0f0426475c",
"label": "temperature",
"name": "Temperature",
"createdAt": "2024-01-15T10:30:00.123456Z"
},
"results": {},
"code": 200
}
]
}{
"start": 1705276800000,
"end": 1705363200000,
"results": [
{
"variable": {
"id": "nonexistent_id"
},
"code": 404,
"message": "Variable or Device not found"
}
]
}{
"detail": "Authentication credentials were not provided."
}Response
Returns an object with start, end, and results. Each item in results corresponds to one requested variable and contains its own code, allowing a single request to partially succeed.
Successful entry fields:
| Field | Description |
|---|---|
| device | Object with url, id, label, name, and createdAt of the Device |
| variable | Object with url, id, label, name, and createdAt of the Variable |
| code | 200 on success |
| results | Object with one key per requested aggregation. Empty object {} if no data exists in the range |
Aggregation result format:
- Aggregations with a specific data point (
first,last,min,max) return{"value": ..., "timestamp": ...} - All other aggregations (
count,sum,mean,std,p25,p50,p75) return{"value": ...}
Error entries (per variable):
| Code | Cause |
|---|---|
| 404 | Variable or Device not found, or no permissions |

