/query 1.x compatibility API
The /query
1.x compatibility endpoint queries InfluxDB Cloud 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.
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
- nanosecondsu
orยต
- microsecondsms
- millisecondss
- secondsm
- minutesh
- hours
Query examples
- Query using basic authentication
- Query a non-default retention policy
- Execute multiple queries
- Return query results with millisecond Unix timestamps
- Execute InfluxQL queries from a file
Query using basic authentication
#######################################
# Use an InfluxDB 1.x compatible username
# and password with Basic Authentication
# to query the InfluxDB 1.x compatibility API
#######################################
# Use default retention policy
#######################################
# Use the --user option with `--user INFLUX_USERNAME:INFLUX_API_TOKEN` syntax
# or the `--user INFLUX_USERNAME` interactive syntax to ensure your credentials are
# encoded in the header.
#######################################
curl --get "http://localhost:8086/query" \
--user "exampleuser@influxdata.com":"INFLUX_API_TOKEN" \
--data-urlencode "db=mydb" \
--data-urlencode "q=SELECT * FROM cpu_usage"
/**
* Use an InfluxDB Cloud username and token
* with Basic Authentication
* to query the InfluxDB 1.x compatibility API
*/
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: 'exampleuser@influxdata.com:INFLUX_API_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();
}