Get Data Statistics

This endpoint computes aggregate statistics for one or more Variables over a time range.

Request

To compute aggregate statistics for one or more Variables, make a POST request to the following URL:

HTTP MethodURL
POSThttps://industrial.api.ubidots.com/api/v2.0/data/statistics/

Body Parameters

ParameterTypeRequired?Description
startIntegerYesStart of the time range as a timestamp in milliseconds (epoch)
endIntegerYesEnd of the time range as a timestamp in milliseconds (epoch). Must be greater than or equal to start
decimalPlacesIntegerNoNumber of decimal places for values (0–16). Defaults to the account setting
variablesObject ArrayYesList of variable references to query. Minimum 1 item. See Variables Array
aggregationsString ArrayNoWhich statistics to compute. Defaults to all 11 types. See Aggregation Types below

Aggregation Types

Each aggregation computes a statistic over the data points in the requested time range. If the aggregations field is omitted, all 11 types are returned.

Aggregations that identify a specific data point (first, last, min, max) include a timestamp alongside the value. All others return only a value.

AggregationDescription
firstFirst value in range (with timestamp)
lastLast value in range (with timestamp)
minMinimum value (with timestamp)
maxMaximum value (with timestamp)
countNumber of data points
sumSum of values
meanAverage
stdStandard deviation
p2525th percentile (approximate)
p50Median (approximate)
p7575th percentile (approximate)

Header

ParameterRequired?Description
X-Auth-TokenYesAuthentication Token of account
$ curl -X POST 'https://industrial.api.ubidots.com/api/v2.0/data/statistics/' \
 -H 'Content-Type: application/json' \
 -H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
 -d '{
    "start": 1705276800000,
    "end": 1705363200000,
    "decimalPlaces": 6,
    "variables": [
        {
            "variable": "64b1c0737e206e0f0426475c"
        },
        {
            "variable": "~temperature",
            "device": "~my-sensor"
        }
    ],
    "aggregations": ["mean", "min", "max", "count"]
}'
{
    "start": 1705276800000,
    "end": 1705363200000,
    "results": [
        {
            "device": {
                "url": "https://industrial.api.ubidots.com/api/v2.0/devices/64a1b2c3d4e5f6a7b8c9d0e1/",
                "id": "64a1b2c3d4e5f6a7b8c9d0e1",
                "label": "my-sensor",
                "name": "My Sensor",
                "createdAt": "2024-01-15T10:30:00.123456Z"
            },
            "variable": {
                "url": "https://industrial.api.ubidots.com/api/v2.0/variables/64b1c0737e206e0f0426475c/",
                "id": "64b1c0737e206e0f0426475c",
                "label": "temperature",
                "name": "Temperature",
                "createdAt": "2024-01-15T10:30:00.123456Z"
            },
            "results": {
                "count": {"value": 100.0},
                "mean": {"value": 25.5},
                "min": {"value": 15.0, "timestamp": 1705300000000},
                "max": {"value": 35.0, "timestamp": 1705350000000}
            },
            "code": 200
        }
    ]
}
{
    "start": 1705276800000,
    "end": 1705363200000,
    "results": [
        {
            "device": {
                "url": "https://industrial.api.ubidots.com/api/v2.0/devices/64a1b2c3d4e5f6a7b8c9d0e1/",
                "id": "64a1b2c3d4e5f6a7b8c9d0e1",
                "label": "my-sensor",
                "name": "My Sensor",
                "createdAt": "2024-01-15T10:30:00.123456Z"
            },
            "variable": {
                "url": "https://industrial.api.ubidots.com/api/v2.0/variables/64b1c0737e206e0f0426475c/",
                "id": "64b1c0737e206e0f0426475c",
                "label": "temperature",
                "name": "Temperature",
                "createdAt": "2024-01-15T10:30:00.123456Z"
            },
            "results": {},
            "code": 200
        }
    ]
}
{
    "start": 1705276800000,
    "end": 1705363200000,
    "results": [
        {
            "variable": {
                "id": "nonexistent_id"
            },
            "code": 404,
            "message": "Variable or Device not found"
        }
    ]
}
{
    "detail": "Authentication credentials were not provided."
}

Response

Returns an object with start, end, and results. Each item in results corresponds to one requested variable and contains its own code, allowing a single request to partially succeed.

Successful entry fields:

FieldDescription
deviceObject with url, id, label, name, and createdAt of the Device
variableObject with url, id, label, name, and createdAt of the Variable
code200 on success
resultsObject with one key per requested aggregation. Empty object {} if no data exists in the range

Aggregation result format:

  • Aggregations with a specific data point (first, last, min, max) return {"value": ..., "timestamp": ...}
  • All other aggregations (count, sum, mean, std, p25, p50, p75) return {"value": ...}

Error entries (per variable):

CodeCause
404Variable or Device not found, or no permissions