Data aggregation

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 MethodURL
POSThttps://industrial.api.ubidots.com/api/v1.6/data/stats/aggregation/

Headers

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

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

Body

An object containing the following 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 POSIX milliseconds format (inclusive).
endNumberNoFinal timestamp in POSIX milliseconds format (inclusive).
tzstringNoThe time zone in which the timestamps provided in the request are interpreted.
precisionintegerNoThe 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 start nor end is 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 the current date.
  • If only end is sent, it will include 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 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."
}