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: [Default] 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).
{
  "variables": ["618848b4b09758ded46bafda", ···, "618848b7b31be1cb509c0a3c"],
  "aggregation": "mean",
  "period": "1H",
  "join_dataframes": false,
  "start": 1636321611000,
  "end": 1636321629000
}

📘

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.

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 every 1 hour from multiple variables:
Get the mean value from multiple variables in a 5 hours time range, resampled every 1 hour.

$ 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",
  "period": "1H",
  "join_dataframes": true,
  "start": 1636304400000,
  "end": 1636322400000
}'
{
  "results": [
    [
      1636322400000,
      null,
      62982.2158
    ],
    [
      1636318800000,
      62858.45385,
      62939.428466666664
    ],
    [
      1636315200000,
      62413.497475000004,
      62514.59343333333
    ],
    [
      1636311600000,
      62399.02165833333,
      62433.42626666667
    ],
    [
      1636308000000,
      62356.53805,
      62445.0895
    ],
    [
      1636304400000,
      62190.30885833333,
      62241.893833333335
    ]
  ],
  "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."
}

Get the mean value every 1 hour from multiple variables:
Get a separate mean value time-series from multiple variables in a 5 hours time range, resampled every 1 hour.

$ 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": false,
  "start": 1636304400000,
  "end": 1636322400000
}'
{
  "results": [
    [
      [
        1636318800000,
        62858.45385
      ],
      [
        1636315200000,
        62413.497475000004
      ],
      [
        1636311600000,
        62399.02165833333
      ],
      [
        1636308000000,
        62356.53805
      ],
      [
        1636304400000,
        62190.30885833333
      ]
    ],
    [
      [
        1636322400000,
        62982.2158
      ],
      [
        1636318800000,
        62939.428466666664
      ],
      [
        1636315200000,
        62514.59343333333
      ],
      [
        1636311600000,
        62433.42626666667
      ],
      [
        1636308000000,
        62445.0895
      ],
      [
        1636304400000,
        62241.893833333335
      ]
    ]
  ],
  "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."
}