Skip to content

Recent measurements

POST {baseUrl}/v2/recent-datasource-measurements-query

By Device

This query is only by Datasource ID. To query by device or reference site, use the historical measurements report.

Returns a list of recent measurements in time descending order.


    org: "myorg1234",
    datasourceIds: ["DS123456", "DS987654"],
    outputFrequency: "hour",

Cached measurements

Recent measurements are served from a fast cache that goes back in time depending on output frequency:

  • Individual measurements (minute) cached for 24 hours
  • Hourly aggregations (hour) cached for 48 hours
  • Daily aggregations (day) cached for 10 days


A common access pattern is to routinely poll to get any new measurements since the last time you asked. It is awkward to accomplish this using startTime on your requests. Due to race conditions it is possible that you could miss a measurement, or get the same measurement twice. To make this easier, a companion endpoint accepts continuation tokens.

In your first call — using this endpoint — you specify an additional parameter: replyWithContinuationToken: true. The response will include an x-clarity-continuation-token in the header.

On subsequent calls, use the recent datasource measurements continuation endpoint and pass that continuation token back in the body (along with org). The continuation response will pick up from the last call, returning newer measurements (if any exist) for the same datasources requested in the first call. An updated continuation token will be returned as well.

You can continue making continuation queries, with the token being updated on each call. A continuation token is good for 24 hours after it is issued.

Note: If the original call was for allDatasources in the org, then the continuations will include/exclude datasources as they are subscribed/unsubscribed.


parameter description
x-api-key string The API key string.
Accept-Encoding string Encoding options, gzip is supported to compress data.

Note: We strongly recommend including it in the headers to reduce response payload size.

Example: Accept-Encoding: gzip


You must include org on all requests. Provide a list of datasources in datasourceIds, or for all the organization's datasources, pass "allDatasources": true.

body parameter description
org string
Find the org ID by clicking on your user icon in Dashboard.
Example org ID: "myorgVD43"
allDatasources bool true to retrieve measurements for all datasources in the specified organization for which you have access.
false or omit the parameter if you want to retrict using datasourceIds.
datasourceIds array of string A list of modern datasource ids as returned from /v2/datasources.
Only measurements from periods when the datasource was subscribed by the requested org are returned.
replyWithContinuationToken bool true if you want to receive a continuation token in the response headers, otherwise omit this parameter
(see Continuations above)

And then add these parameters

additional query parameter description
outputFrequency string The output frequency of the aggregations to return in the measurement. One of:
"minute" default - returns individual measurements, with no aggregation applied.
"hour" returns 1-Hour Mean, 24-Hour Rolling Mean and NowCast aggregations, and AQIs which are calculated on these aggregations as per their standard.
"day" returns 24-Hour Mean aggregations, and AQIs which are calculated on these aggregations as per their standard.
format string The format of the response. One of:
json-long default - A JSON object per metric in a measurement
csv-wide CSV, one row per measurement
startTime string Cut-off time for the earliest measurement desired. If not specified, the start time used will be chosen based on the requested output frequency
minute → 1 hour prior to time of request
hour → 24 hours prior to time of request
day → 48 hours prior to time of request

Measurements are returned from a cache. Earlier times are accepted in the parameter, but only data from the cache will be returned.

Example: startTime: "2023-09-01T00:00:00Z"
metricSelect string Limits the metrics returned in the measurement. See Metrics selection

Response Headers

parameter description
x-clarity-continuation-token string The continuation token, if it was requested with replyWithContinuationToken

Response Formats


A typical JSON structure including these important objects

  • request - an echo back of the original request
  • data - a list of metrics objects
  • locations - a sidebar dictionary to lookup the location of a datasource

This example is an excerpt of a much longer response:

    "request": {
        "format": "json-long",
        "org": "myorg1234",
        "outputFrequency": "hour",
        "allDatasources": true,
        "startTime": "2023-11-03T19:00:00+00:00"

    "data": [
            "time": "2023-11-03T19:00:00.000Z",
            "status": "sensor-ready",
            "value": 20.25,
            "raw": 20.25,
            "metric": "temperatureInternal1HourMean",
            "datasourceId": "DCQYT1459"
            "time": "2023-11-03T19:00:00.000Z",
            "status": "calibrated-ready",
            "value": 30.41,
            "raw": 30.89,
            "metric": "pm2_5ConcMass1HourMean",
            "datasourceId": "DCQYT1459"

    "locations": [
            "datasourceId": "DCQYT1459",
            "lon": -122.30173,
            "lat": 37.87864
            "datasourceId": "DDDYN3547",
            "lon": -116.7845,
            "lat": 38.28068

Note: Best practice is that if a device in a datasource is replaced, the new device should be configured to the same location as the old device. If that does not happen, then it is possible for location to change in the middle of a time-series. If that should occur, then the locations object above will show both locations and identify the first measurement in the time-series that has the new location:

            "datasourceId": "DABCD1234",
            "lon": -120.24056,
            "lat": 37.87864
            "datasourceId": "DABCD1234",               <--- same datasource
            "lon": -122.00052,                         <--- new location
            "lat": 38.28068,
            "startingAt": "2023-11-03T21:00:00.000Z"   <--- first measurement at new location


Column Headers

Automation that processes this response should not assume specifc columns or column ordering. Interpret based on the header row of the response.

The response is like a CSV file: A comma-separated string with an initial header row identifying the columns and with newlines separating the measurements. The set of columns returned depends on the outputFrequency requested.

Identifying columns for all output frequencies:

column header description
datasourceId Unique identifier of the datasource. (string)
sourceId Unique identifier of the underlying device or reference site. (string)
sourceType Either CLARITY_NODE or REFERENCE_SITE. (string)
outputFrequency The output frequency; one of minute, hour, or day. (string)



Example code

Slicing specific columns from CSV

The following sample Python code selects just the columns you want and converts to native Python types.

# simple demo using Clarity Data API

import requests
import os
import csv
import pprint
import datetime

    'Accept-Encoding': 'gzip',
    'x-api-key': os.environ.get('MY_CLARITY_API_KEY') # put your key in the environment or directly here

def check_can_connect():
    # verify can reach the API
    response = requests.get(BASEURL, HEADERS)
    http_code = response.status_code
    connected = (http_code == 200)
    if connected:
        print('Connected to Clarity')
        print(f'{http_code}  :(  Cannot connect')

def get_recent_measurements(org, datasource_ids, output_frequency, format, metric_selector):
    # Fetch measurements from the API
    url = BASEURL + '/v2/recent-datasource-measurements-query'
    request_body = {
        'org': org,
        'datasourceIds': datasource_ids,
        'outputFrequency': output_frequency,
        'format': format,
        'metricSelect': metric_selector
    response =, headers=HEADERS, json=request_body)
    return response.text

def csv_to_typed(csv_data, fields_to_extract):
    # slice specific columns out of the CSV-style response
    # convert each to best Python type
    # return dictionary

    def convert_to_best_type(value):
        # Try these types in order: float, datetime, else string
            return float(value)
        except Exception:
                return datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ')
            except Exception:
                return value

    reader = csv.DictReader(csv_data.splitlines())
    return [{field: convert_to_best_type(row[field]) for field in fields_to_extract} for row in reader]


tabular = get_recent_measurements(
        metric_selector='only pm2_5ConcMass1HourMean'

measurements = csv_to_typed(tabular, [