Data resample

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

To resample data from one or multiple variables over a time range with a given resampling period, make a POST request to the following URL:

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

Headers

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

HeaderValueRequired?Description
X-Auth-TokenTokenYesThe account's authentication token.
Content-Typeapplication/jsonYesThe content type of the request body.

Body

The request body is 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.
periodStringYesResampling period. See the note below for a detailed explanation.
join_dataframesBooleanNotrue: returns an array where each element contains the values for the period.
false: returns an array where each element is a separate time series for a variable.
startNumberNoInitial timestamp in POSIX format, in milliseconds (inclusive).
endNumberNoFinal timestamp in POSIX format, in milliseconds (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",
  "period": "1H",
  "join_dataframes": false,
  "start": 1636321611000,
  "end": 1636321629000,
  "tz" : "America/New_York",
  "precision" : 2
}
📘

Period parameter

Available resampling 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 nor end is included, the request uses the last 100 values of each variable.
  • If only start is sent, the request includes values from that timestamp up to the current date.
  • If only end is sent, the request includes values from the beginning of data reception up to that timestamp.
  • If the precision key is not defined, decimal numbers are displayed according to the calculation.

Query Parameters

You may add optional parameters to the request URL:

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

Resample every 1 hour and return a combined time-aligned dataset
Get the mean value from multiple variables over a 5-hour time range, resampled every 1 hour. The response returns a single, combined dataset aligned by timestamp.

$ 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,
  "tz" : "America/New_York",
  "precision" : 2
}'
{
  "results": [
    [
      1636322400000,
      null,
      62982.21
    ],
    [
      1636318800000,
      62858.45,
      62939.42
    ],
    [
      1636315200000,
      62413.49,
      62514.59
    ],
    [
      1636311600000,
      62399.02,
      62433.42
    ],
    [
      1636308000000,
      62356.53,
      62445.08
    ],
    [
      1636304400000,
      62190.30,
      62241.89
    ]
  ],
  "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."
}

Resample every 1 hour and return separate time-series per variable
Get the mean value from multiple variables over a 5-hour time range, resampled every 1 hour. The response returns independent time-series for each variable.

$ 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": false,
  "start": 1636304400000,
  "end": 1636322400000,
  "tz": "America/New_York",
  "precision": 2
}'
{
  "results": [
    [
      [
        1636318800000,
        62858.45
      ],
      [
        1636315200000,
        62413.49
      ],
      [
        1636311600000,
        62399.02
      ],
      [
        1636308000000,
        62356.53
      ],
      [
        1636304400000,
        62190.30
      ]
    ],
    [
      [
        1636322400000,
        62982.21
      ],
      [
        1636318800000,
        62939.42
      ],
      [
        1636315200000,
        62514.59
      ],
      [
        1636311600000,
        62433.42
      ],
      [
        1636308000000,
        62445.08
      ],
      [
        1636304400000,
        62241.89
      ]
    ]
  ],
  "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."
}