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 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 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.

join_dataframes

Boolean

No

true: returns a single value.
false: [Default] returns a value 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",
  "join_dataframes": false,
  "start": 1636321611000,
  "end": 1636321629000
}

📘

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.

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 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
}'
{
  "results": [
    {
      "value": 62873.888306249995,
      "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
}'
{
  "results": [
    {
      "value": 62858.45385000001,
      "timestamp": 1636318807253
    },
    {
      "value": 62920.191675,
      "timestamp": 1636318800000
    }
  ]
}
{
  "detail": "JSON parse error - Expecting value: line 4 column 22 (char 121)"
}
{
  "code": 401001,
  "message": "Authentication credentials were not provided."
}