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 with a given resample period within a time range, please 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 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.
periodStringYesResampling period. See note below for detailed explanation.
join_dataframesBooleanNotrue: returns an array. Each element is an array containing the values for the period.
false: {
"h
returns an array where each element is separate time-series 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",
  "period": "1H",
  "join_dataframes": false,
  "start": 1636321611000,
  "end": 1636321629000,
  "tz" : "America/New_York",
  "precision" : 2
}
📘

Period parameter

Available resample 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 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

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