Documentation

/query 1.x compatibility API

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

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.

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
#######################################
# Use Basic authentication with an
# InfluxDB 1.x compatible username and password
# to query the InfluxDB 1.x compatibility API.
#
# Replace INFLUX_USERNAME with your 1.x-compatible username.
# Replace INFLUX_PASSWORD_OR_TOKEN with your InfluxDB API token
# or 1.x-compatible password.
#######################################
# Use the default retention policy.
#######################################
# Use the --user option with `--user <username>:<password>` syntax
# or the `--user <username>` interactive syntax to ensure your credentials are
# encoded in the header.
#######################################

curl --get "http://localhost:8086/query" \
  --user "INFLUX_USERNAME":"INFLUX_PASSWORD_OR_TOKEN" \
  --data-urlencode "db=mydb" \
  --data-urlencode "q=SELECT * FROM cpu_usage"
/**
  * Use Basic authentication with an
  * InfluxDB 1.x compatible username and password
  * to query the InfluxDB 1.x compatibility API.

  * Replace INFLUX_USERNAME with your 1.x-compatible username.
  * Replace INFLUX_PASSWORD_OR_TOKEN with your InfluxDB API token
  * or 1.x-compatible password.
  * Use the default retention policy.
  */

const https = require('https');
const querystring = require('querystring');

function queryWithUsername() {
  const queryparams = {
      db: 'mydb',
      q: 'SELECT * FROM cpu_usage',
  };

  const options = {
    host: 'localhost:8086',
    path: '/query?' + querystring.stringify(queryparams),
    auth: 'INFLUX_USERNAME:INFLUX_PASSWORD_OR_TOKEN',
    headers: {
      'Content-type': 'application/json'
    },
  };

  const request = https.get(options, (response) => {
    let rawData = '';
    response.on('data', () => {
      response.on('data', (chunk) => { rawData += chunk; });
    })
    response.on('end', () => {
      console.log(rawData);
    })
  });

  request.end();
}
Query a non-default retention policy
curl --get http://localhost:8086/query \
  --header "Authorization: Token INFLUX_API_TOKEN" \
  --data-urlencode "db=mydb" \
  --data-urlencode "rp=customrp" \
  --data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1"
Execute multiple queries
curl --get http://localhost:8086/query \
  --header "Authorization: Token INFLUX_API_TOKEN" \
  --data-urlencode "db=mydb" \
  --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
curl --get http://localhost:8086/query \
  --header "Authorization: Token INFLUX_API_TOKEN" \
  --data-urlencode "db=mydb" \
  --data-urlencode "rp=myrp" \
  --data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1" \
  --data-urlencode "epoch=ms"
Execute InfluxQL queries from a file
curl --get http://localhost:8086/query \
  --header "Authorization: Token INFLUX_API_TOKEN" \
  --data-urlencode "db=mydb" \
  --data-urlencode "q@path/to/influxql.txt" \
  --data-urlencode "async=true"

Replace the following:

  • INFLUX_API_TOKEN: InfluxDB API token

Was this page helpful?

Thank you for your feedback!


Introducing InfluxDB Clustered

A highly available InfluxDB 3.0 cluster on your own infrastructure.

InfluxDB Clustered is a highly available InfluxDB 3.0 cluster built for high write and query workloads on your own infrastructure.

InfluxDB Clustered is currently in limited availability and is only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Learn more
Contact InfluxData Sales

The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following:

State of the InfluxDB Cloud Serverless documentation

InfluxDB Cloud Serverless documentation is a work in progress.

The new documentation for InfluxDB Cloud Serverless is a work in progress. We are adding new information and content almost daily. Thank you for your patience!

If there is specific information you’re looking for, please submit a documentation issue.