/query 1.x compatibility API

This page documents an earlier version of InfluxDB. InfluxDB v2.7 is the latest stable version. View this page in the v2.7 documentation.

The /query 1.x compatibility endpoint queries InfluxDB Cloud and InfluxDB OSS 2.3 using InfluxQL. Use the GET request method to query data from the /query endpoint.

  1. GET http://localhost:8086/query

The /query compatibility endpoint uses the database and retention policy specified in the query request to map the request to an InfluxDB bucket. For more information, see Database and retention policy mapping.

If you have an existing bucket that doesn’t follow the database/retention-policy naming convention, you must manually create a database and retention policy mapping to query that bucket with the /query compatibility API.

Authentication

Use one of the following authentication methods:

  • token authentication
  • basic authentication with username and password
  • query string authentication with username and password

For more information, see Authentication.

Query string parameters

u

(Optional) The 1.x username to authenticate the request. See query string authentication.

p

(Optional) The 1.x password to authenticate the request. See query string authentication.

db

(Required) The database to query data from. This is mapped to an InfluxDB bucket. See Database and retention policy mapping.

rp

The retention policy to query data from. This is mapped to an InfluxDB bucket. See Database and retention policy mapping.

q

(Required) The InfluxQL query to execute. To execute multiple queries, delimit queries with a semicolon (;).

epoch

Return results with Unix timestamps (also known as epoch timestamps) in the specified precision instead of RFC3339 timestamps with nanosecond precision. The following precisions are available:

  • ns - nanoseconds
  • u or µ - microseconds
  • ms - milliseconds
  • s - seconds
  • m - minutes
  • h - hours

Query examples

Query using basic authentication

curl Node.js

  1. #######################################
  2. # Use Basic authentication with an
  3. # InfluxDB 1.x compatible username and password
  4. # to query the InfluxDB 1.x compatibility API.
  5. #
  6. # Replace INFLUX_USERNAME with your 1.x-compatible username.
  7. # Replace INFLUX_PASSWORD_OR_TOKEN with your InfluxDB API token
  8. # or 1.x-compatible password.
  9. #######################################
  10. # Use the default retention policy.
  11. #######################################
  12. # Use the --user option with `--user <username>:<password>` syntax
  13. # or the `--user <username>` interactive syntax to ensure your credentials are
  14. # encoded in the header.
  15. #######################################
  16. curl --get "http://localhost:8086/query" \
  17. --user "INFLUX_USERNAME":"INFLUX_PASSWORD_OR_TOKEN" \
  18. --data-urlencode "db=mydb" \
  19. --data-urlencode "q=SELECT * FROM cpu_usage"
  1. /**
  2. * Use Basic authentication with an
  3. * InfluxDB 1.x compatible username and password
  4. * to query the InfluxDB 1.x compatibility API.
  5. * Replace INFLUX_USERNAME with your 1.x-compatible username.
  6. * Replace INFLUX_PASSWORD_OR_TOKEN with your InfluxDB API token
  7. * or 1.x-compatible password.
  8. * Use the default retention policy.
  9. */
  10. const https = require('https');
  11. const querystring = require('querystring');
  12. function queryWithUsername() {
  13. const queryparams = {
  14. db: 'mydb',
  15. q: 'SELECT * FROM cpu_usage',
  16. };
  17. const options = {
  18. host: 'localhost:8086',
  19. path: '/query?' + querystring.stringify(queryparams),
  20. auth: 'INFLUX_USERNAME:INFLUX_PASSWORD_OR_TOKEN',
  21. headers: {
  22. 'Content-type': 'application/json'
  23. },
  24. };
  25. const request = https.get(options, (response) => {
  26. let rawData = '';
  27. response.on('data', () => {
  28. response.on('data', (chunk) => { rawData += chunk; });
  29. })
  30. response.on('end', () => {
  31. console.log(rawData);
  32. })
  33. });
  34. request.end();
  35. }
Query a non-default retention policy
  1. curl --get http://localhost:8086/query \
  2. --header "Authorization: Token INFLUX_API_TOKEN" \
  3. --data-urlencode "db=mydb" \
  4. --data-urlencode "rp=customrp" \
  5. --data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1"
Execute multiple queries
  1. curl --get http://localhost:8086/query \
  2. --header "Authorization: Token INFLUX_API_TOKEN" \
  3. --data-urlencode "db=mydb" \
  4. --data-urlencode "q=SELECT * FROM mem WHERE host=host1;SELECT mean(used_percent) FROM mem WHERE host=host1 GROUP BY time(10m)"
Return query results with millisecond Unix timestamps
  1. curl --get http://localhost:8086/query \
  2. --header "Authorization: Token INFLUX_API_TOKEN" \
  3. --data-urlencode "db=mydb" \
  4. --data-urlencode "rp=myrp" \
  5. --data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1" \
  6. --data-urlencode "epoch=ms"
Execute InfluxQL queries from a file
  1. curl --get http://localhost:8086/query \
  2. --header "Authorization: Token INFLUX_API_TOKEN" \
  3. --data-urlencode "db=mydb" \
  4. --data-urlencode "q@path/to/influxql.txt" \
  5. --data-urlencode "async=true"

Replace the following:

  • INFLUX_API_TOKEN: InfluxDB API token

influxql query