Use this endpoint to aggregate data from one or multiple variables in a time range
To aggregate data from one or more variables into a single value or a value per variable, make a POST request to the following URL:
| HTTP Method | URL |
|---|---|
| POST | https://industrial.api.ubidots.com/api/v1.6/data/stats/aggregation/ |
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 for the account. |
Content-Type | application/json | Yes | The data type of the body. |
Body
An object containing the following parameters:
| Parameter | Type | Required? | Description |
|---|---|---|---|
| variables | String Array | Yes | An array of variable IDs |
| aggregation | String | Yes | The aggregation to apply. Possible values are mean, min, max, count, sum. |
| join_dataframes | Boolean | No | true: returns a single value.false: [Default] returns a value per variable. |
| start | Number | No | Initial timestamp in POSIX milliseconds format (inclusive). |
| end | Number | No | Final timestamp in POSIX milliseconds format (inclusive). |
| tz | string | No | The time zone in which the timestamps provided in the request are interpreted. |
| precision | integer | No | The number of decimal places to use for data aggregation. |
{
"variables": ["618848b4b09758ded46bafda", ···, "618848b7b31be1cb509c0a3c"],
"aggregation": "mean",
"join_dataframes": false,
"start": 1636321611000,
"end": 1636321629000,
"tz": "America/New_York",
"precision": 2
}
Optional parameters
- If neither
startnorendis included, the request will use the last 100 values of each variable.- If only
startis sent, it will include values from that timestamp up until the current date.- If only
endis sent, it will include values from the beginning of data reception up until that timestamp.- If the
precisionkey is not defined, decimal numbers will be displayed according to the calculation.
Query Parameters
You may add optional parameters to the URL of your request:
| Parameter | Type | Description |
|---|---|---|
| token | String | The token to authenticate the request. While sending it as a query parameter is supported, we strongly recommend using the X-Auth-Token header. |
Examples
Get the mean value across multiple variables:
Get the mean value across multiple variables in a 1-hour time range.
$ curl -X POST 'https://industrial.api.ubidots.com/api/v1.6/data/stats/aggregation/' \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
-d '{
"variables": ["618848b4b09758ded46bafda", "618848b7b31be1cb509c0a3c"],
"aggregation": "mean",
"join_dataframes": true,
"start": 1636321611000,
"end": 1636321629000,
"tz": "America/New_York",
"precision": 2
}'{
"results": [
{
"value": 62873.88,
"timestamp": 1636318800000
}
]
}{
"detail": "JSON parse error - Expecting value: line 4 column 22 (char 121)"
}{
"code": 401001,
"message": "Authentication credentials were not provided."
}Get the mean value for multiple variables:
Get the mean value for multiple variables in a 1-hour time range.
$ curl -X POST 'https://industrial.api.ubidots.com/api/v1.6/data/stats/aggregation/' \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
-d '{
"variables": ["618848b4b09758ded46bafda", "618848b7b31be1cb509c0a3c"],
"aggregation": "mean",
"join_dataframes": true,
"start": 1636321611000,
"end": 1636321629000,
"tz": "America/New_York",
"precision": 2
}'{
"results": [
{
"value": 62858.45,
"timestamp": 1636318807253
},
{
"value": 62920.19,
"timestamp": 1636318800000
}
]
}{
"detail": "JSON parse error - Expecting value: line 4 column 22 (char 121)"
}{
"code": 401001,
"message": "Authentication credentials were not provided."
}
