Use this endpoint to aggregate data from one or multiple variables in a time range

To aggregate data from one or multiple variables into a single value or a value per variable, please make a POST request to the following URL:

HTTP MethodURL
POSThttps://industrial.api.ubidots.com/api/v1.6/data/stats/aggregation/

Headers

The "X-Auth-Token" and "Content-Type" headers are required to your request:

HeaderValueRequired?Description
X-Auth-TokenTokenYesAuthentication Token of account.
Content-Typeapplication/jsonYesThe type of data of the body.

Body

An object containing the following key parameters:

ParameterTypeRequired?Description
variablesString ArrayYesAn array of variable IDs
aggregationStringYesThe aggregation to apply. Possible values are mean, min, max, count, sum.
join_dataframesBooleanNotrue: returns a single value.
false: [Default] returns a value per variable
startNumberNoInitial timestamp in milliseconds POSIX format (inclusive).
endNumberNoFinal timestamp in milliseconds POSIX format (inclusive).
tzstringNoThe timezone in which the timestamps provided in the request are interpreted.
precisionintegerNoThe decimal places to be used 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 start and end 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.
  • If the precision key 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:

ParameterTypeDescription
tokenStringThe 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 mean value across multiple variables:
Get mean value across multiple variables in 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 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."
}