TL;DR InfluxDB Tech Tips - HTTP API: Return Query Results & Authenticating Requests

Navigate to:

In this post we recap the week’s most interesting InfluxDB and TICK-stack related issues, workarounds, how-tos and Q&A from GitHub, IRC and the InfluxDB Google Group that you might have missed.

Chunking query responses with the HTTP API

Q: Is there a way to return query responses in batches rather than as a single response?

A: Yes! The HTTP API query string parameter chunked=true tells InfluxDB to return points in streamed batches instead of in a single response. If set to true, InfluxDB chunks responses by series or by every 10,000 points, whichever occurs first. If set to a specific value (for example, chunked=20000), InfluxDB chunks responses by series or by that number of points.

See the API Reference doc for more on query string parameters.

Using OR with absolute time in the WHERE clause

Q: I’m trying to query for points that have specific timestamps. I can see that I’ve successfully written the points but my query returns no results. Is there something that I’m doing wrong?

> SELECT * FROM "heaven"
name: heaven
------------
time                   cherrypie
2016-08-24T20:00:00Z   1
2016-08-24T20:10:00Z   4

> SELECT * FROM "heaven" WHERE time = '2016-08-24T20:00:00Z' OR time = '2016-08-24T20:10:00Z'

A: Currently, InfluxQL does not support using OR with absolute time in the WHERE clause. InfluxDB returns an empty response if the query’s WHERE clause uses OR with absolute time.

In the meantime you can split your query into two queries:

> SELECT * FROM "heaven" WHERE time = '2016-08-24T20:00:00Z'
name: heaven
------------
time                   cherrypie
2016-08-24T20:00:00Z   1

> SELECT * FROM "heaven" WHERE time = '2016-08-24T20:10:00Z'
name: heaven
------------
time                   cherrypie
2016-08-24T20:10:00Z   4

Or you can use AND instead of OR:

> SELECT * FROM "heaven" WHERE time >= '2016-08-24T20:00:00Z' AND time <= '2016-08-24T20:10:00Z'
name: heaven
------------
time                   cherrypie
2016-08-24T20:00:00Z   1
2016-08-24T20:10:00Z   4

See GitHub Issue #3290 to track this issue.

Authenticating requests with the HTTP API

Q: I’ve enabled authentication in my configuration file. How do I authenticate requests with the HTTP API?

A: InfluxDB’s HTTP API supports HTTP authentication and basic authentication.

Your first option is to use the query string parameters u and p:

curl -i -XPOST "http://localhost:8086/write?db=topsecret&u=myusername&p=mypassword" --data-binary 'manila_envelope,location=confidential number=91'

Your second option is to use basic authentication:

curl -i -XPOST -u myusername:mypassword "http://localhost:8086/write?db=topsecret" --data-binary 'manila_envelope,location=confidential number=91'

Check out the API Reference doc for more on using the API.

For more InfluxDB tips, see our Frequently Asked Questions page and feel free to post your questions in the InfluxDB users group.

What's next?