Documentation

Query with the InfluxDB API

The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. To query InfluxDB Cloud, do one of the following:

In your request, set the following:

  • Your organization via the org or orgID URL parameters.
  • Authorization header to Token + your API token.
  • Accept header to application/csv.
  • Content-type header to application/vnd.flux (Flux only) or application/json (Flux or InfluxQL).
  • Query in Flux or InfluxQL with the request’s raw data.

Use gzip to compress the query response

To compress the query response, set the Accept-Encoding header to gzip. This saves network bandwidth, but increases server-side load.

We recommend only using gzip compression on responses that are larger than 1.4 KB. If the response is smaller than 1.4 KB, gzip encoding will always return a 1.4 KB response, despite the uncompressed response size. 1500 bytes (~1.4 KB) is the maximum transmission unit (MTU) size for the public network and is the largest packet size allowed at the network layer.

Flux - Example query request

Below is an example curl request that sends a Flux query to InfluxDB Cloud:

curl --request POST \
  http://localhost:8086/api/v2/query?orgID=INFLUX_ORG_ID  \
  --header 'Authorization: Token INFLUX_TOKEN' \
  --header 'Accept: application/csv' \
  --header 'Content-type: application/vnd.flux' \
  --data 'from(bucket:"example-bucket")
        |> range(start: -12h)
        |> filter(fn: (r) => r._measurement == "example-measurement")
        |> aggregateWindow(every: 1h, fn: mean)'
curl --request POST \
  http://localhost:8086/api/v2/query?orgID=INFLUX_ORG_ID \
  --header 'Authorization: Token INFLUX_TOKEN' \
  --header 'Accept: application/csv' \
  --header 'Content-type: application/vnd.flux' \
  --header 'Accept-Encoding: gzip' \
  --data 'from(bucket:"example-bucket")
        |> range(start: -12h)
        |> filter(fn: (r) => r._measurement == "example-measurement")
        |> aggregateWindow(every: 1h, fn: mean)'

InfluxQL - Example query request

Below is an example curl request that sends an InfluxQL query to InfluxDB Cloud:

curl --request -G http://localhost:8086/query?orgID=INFLUX_ORG_ID&database=MyDB&retention_policy=MyRP \
  --header 'Authorization: Token INFLUX_TOKEN' \
  --header 'Accept: application/csv' \
  --header 'Content-type: application/json' \
  --data-urlencode "q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1"
curl --request -G http://localhost:8086/query?orgID=INFLUX_ORG_ID&database=MyDB&retention_policy=MyRP \
  --header 'Authorization: Token INFLUX_TOKEN' \
  --header 'Accept: application/csv' \
  --header 'Content-type: application/json' \
  --header 'Accept-Encoding: gzip' \
  --data-urlencode "q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1"

InfluxDB returns the query results in annotated CSV.


Was this page helpful?

Thank you for your feedback!


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.

Read more

InfluxDB v3 enhancements and InfluxDB Clustered is now generally available

New capabilities, including faster query performance and management tooling advance the InfluxDB v3 product line. InfluxDB Clustered is now generally available.

InfluxDB v3 performance and features

The InfluxDB v3 product line has seen significant enhancements in query performance and has made new management tooling available. These enhancements include an operational dashboard to monitor the health of your InfluxDB cluster, single sign-on (SSO) support in InfluxDB Cloud Dedicated, and new management APIs for tokens and databases.

Learn about the new v3 enhancements


InfluxDB Clustered general availability

InfluxDB Clustered is now generally available and gives you the power of InfluxDB v3 in your self-managed stack.

Talk to us about InfluxDB Clustered

InfluxDB Cloud powered by TSM