Data query API

Our storage server is powered by InfluxDB, an open-source time series database engine. We expose its HTTP API for querying the measurement data.

Connection parameters

  • HTTP URL:

    https://[YOUR_DOMAIN].decentlab.com/api/datasources/proxy/1/query?db=main&epoch=ms&q=[YOUR_QUERY]
    

The URL parameter values, db=main (database name) and epoch=ms (millisecond-resolution timestamps) reflect the most common cases. Nevertheless, you may modify them according to the InfluxDB specification for your special needs.

  • Additional HTTP Header:

    Authorization: Bearer [YOUR_API_KEY]
    

This additional HTTP header represents your credential to access the database. Please contact us if you haven’t received an API key already.

The following example shows how to access the HTTP API using curl with our demo server. --data-urlencode 'pretty=true' enables a pretty-printed output, which is useful only for debugging purposes.

$ curl -G \
       -H 'Authorization: Bearer eyJrIjoiclhMRFFvUXFzQXpKVkZydm52b0VMRVg3M3U2b3VqQUciLCJuIjoiZGF0YS1xdWVyeS1hcGktZGVtby0yIiwiaWQiOjF9' \
       --data-urlencode 'q=SELECT value FROM "measurements" LIMIT 1' \
       --data-urlencode 'pretty=true' \
       'https://demo.decentlab.com/api/datasources/proxy/1/query?db=main&epoch=ms'
{
    "results": [
        {
            "series": [
                {
                    "name": "measurements",
                    "columns": [
                        "time",
                        "value"
                    ],
                    "values": [
                        [
                            1464383631403,
                            7
                        ]
                    ]
                }
            ]
        }
    ]
}

Note

InfluxDB supports only JSON-formatted output which may require format conversions for your specific environment.

Query language

InfluxDB provides a time series-oriented special query language, InfluxQL. Although InfluxQL is similar to the generic SQL, there are significant differences. You may need to consult the documentation.

Besides simple data retrievals, InfluxQL supports many useful mathematical and statistical functions executed on the server. Using such server-side processing functions can significantly reduce communication overheads and therefore increase overall system performance.

Reference implementations

To boost your development, we provide reference implementations for common environments.

Please feel free to integrate and adapt these implementations into your data processing tools. We would be pleased to receive your feedback.