/query 1.x compatibility API
The /query
1.x compatibility endpoint queries InfluxDB Cloud and InfluxDB OSS 2.0 using InfluxQL. Use the GET
request method to query data from the /query
endpoint.
GET https://cloud2.influxdata.com/query
The /query
compatibility endpoint use 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 does’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 basic authentication or token authentication. For more information, see Authentication.
Query string parameters
URL-encode all query string parameters.
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
- Use
curl
to execute InfluxQL queries from a file
Query using basic authentication
curl --request GET https://cloud2.influxdata.com/query \
--user "username:YourAuthToken" \
--data-urlencode "db=mydb" \
--data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1"
Query a non-default retention policy
curl --request GET https://cloud2.influxdata.com/query \
--header "Authorization: Basic username:YourAuthToken" \
--data-urlencode "db=mydb" \
--data-urlencode "rp=customrp" \
--data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1"
Execute multiple queries
curl --request GET https://cloud2.influxdata.com/query \
--header "Authorization: Token YourAuthToken" \
--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 --request GET https://cloud2.influxdata.com/query \
--header "Authorization: Token YourAuthToken" \
--data-urlencode "db=mydb" \
--data-urlencode "rp=myrp" \
--data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1" \
--data-urlencode "epoch=ms"
Use curl to execute InfluxQL queries from a file
curl --request GET https://cloud2.influxdata.com/query \
--header "Authorization: Token YourAuthToken" \
--data-urlencode "db=mydb" \
--form "q=@path/to/influxql.txt" \
--form "async=true"