Use this endpoint to resample data from one or multiple variables in a time range
To resample data from one or multiple variables with a given resample period within a time range, please make a POST request to the following URL:
HTTP Method | URL |
---|---|
POST | https://industrial.api.ubidots.com/api/v1.6/data/stats/resample/ |
Headers
The "X-Auth-Token" and "Content-Type" headers are required to your request:
Header | Value | Required? | Description |
---|---|---|---|
X-Auth-Token | Token | Yes | Authentication Token of account. |
Content-Type | application/json | Yes | The type of data of the body. |
Body
An object containing the following key 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 . |
period | String | Yes | Resampling period. See note below for detailed explanation. |
join_dataframes | Boolean | No | true : returns an array. Each element is an array containing the values for the period.false : {"h returns an array where each element is separate time-series per variable. |
start | Number | No | Initial timestamp in milliseconds POSIX format (inclusive). |
end | Number | No | Final timestamp in milliseconds POSIX format (inclusive). |
{
"variables": ["618848b4b09758ded46bafda", ···, "618848b7b31be1cb509c0a3c"],
"aggregation": "mean",
"period": "1H",
"join_dataframes": false,
"start": 1636321611000,
"end": 1636321629000
}
Period parameter
Available resample periods are:
- "nT" : Every n minutes
- "nH" : Every n hours
- "nD" : Every n days
- "W" : Every end of week
- "M" : Every end of month
Optional parameters
- If neither
start
andend
are included, the request will use the last 100 values of each variable.- If only
start
is sent, it will include values from that timestamp up until current date.- If only
end
is sent, it will includes values from the beginning of data reception up until that timestamp.
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 every 1 hour from multiple variables:
Get the mean value from multiple variables in a 5 hours time range, resampled every 1 hour.
$ curl -X POST 'https://industrial.api.ubidots.com/api/v1.6/data/stats/resample/' \
-H 'Content-Type: application/json' \
-H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
-d '{
"variables": ["618848b4b09758ded46bafda", "618848b7b31be1cb509c0a3c"],
"aggregation": "mean",
"period": "1H",
"join_dataframes": true,
"start": 1636304400000,
"end": 1636322400000
}'
{
"results": [
[
1636322400000,
null,
62982.2158
],
[
1636318800000,
62858.45385,
62939.428466666664
],
[
1636315200000,
62413.497475000004,
62514.59343333333
],
[
1636311600000,
62399.02165833333,
62433.42626666667
],
[
1636308000000,
62356.53805,
62445.0895
],
[
1636304400000,
62190.30885833333,
62241.893833333335
]
],
"columns": [
"timestamp",
"618848b4b09758ded46bafda.value.value",
"618848b7b31be1cb509c0a3c.value.value"
]
}
{
"detail": "JSON parse error - Expecting value: line 4 column 22 (char 121)"
}
{
"code": 401001,
"message": "Authentication credentials were not provided."
}
Get the mean value every 1 hour from multiple variables:
Get a separate mean value time-series from multiple variables in a 5 hours time range, resampled every 1 hour.
$ 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": false,
"start": 1636304400000,
"end": 1636322400000
}'
{
"results": [
[
[
1636318800000,
62858.45385
],
[
1636315200000,
62413.497475000004
],
[
1636311600000,
62399.02165833333
],
[
1636308000000,
62356.53805
],
[
1636304400000,
62190.30885833333
]
],
[
[
1636322400000,
62982.2158
],
[
1636318800000,
62939.428466666664
],
[
1636315200000,
62514.59343333333
],
[
1636311600000,
62433.42626666667
],
[
1636308000000,
62445.0895
],
[
1636304400000,
62241.893833333335
]
]
],
"columns": [
[
"timestamp",
"value.value"
],
[
"timestamp",
"value.value"
]
]
}
{
"detail": "JSON parse error - Expecting value: line 4 column 22 (char 121)"
}
{
"code": 401001,
"message": "Authentication credentials were not provided."
}