Query

Download InfluxDB API Spec
Retrieve data, analyze queries, and get query suggestions.
POST /api/v2/query

Query data

Retrieves data from buckets.

Use this endpoint to send a Flux query request and retrieve data from a bucket.

Rate limits (with InfluxDB Cloud)

read rate limits apply. For more information, see limits and adjustable quotas.

Parameters

Query parameters
org string

An organization name or ID.

InfluxDB Cloud

  • Doesn’t use the org parameter or orgID parameter.
  • Queries the bucket in the organization associated with the authorization (API token).

InfluxDB OSS

  • Requires either the org parameter or orgID parameter.
  • Queries the bucket in the specified organization.
orgID string

An organization ID.

InfluxDB Cloud

  • Doesn’t use the org parameter or orgID parameter.
  • Queries the bucket in the organization associated with the authorization (API token).

InfluxDB OSS

  • Requires either the org parameter or orgID parameter.
  • Queries the bucket in the specified organization.
Header parameters
Zap-Trace-Span string
OpenTracing span context
Accept-Encoding string
The content encoding (usually a compression algorithm) that the client can understand.
Allowed values: gzip , identity
Default: identity
Content-Type string
Allowed values: application/json , application/vnd.flux

Request body

Flux query or specification to execute
Content-Type: application/json
dialect object

Options for tabular data output. Default output is annotated CSV with headers.

For more information about tabular data dialect, see W3 metadata vocabulary for tabular data.

annotations string[]

Annotation rows to include in the results. An annotation is metadata associated with an object (column) in the data model.

For more information about annotations in tabular data, see W3 metadata vocabulary for tabular data.

commentPrefix string
The character prefixed to comment strings. Default is a number sign (#).
Default: #
dateTimeFormat string

The format for timestamps in results. Default is RFC3339 date/time format. To include nanoseconds in timestamps, use RFC3339Nano.

Example formatted date/time values

FormatValue
RFC3339"2006-01-02T15:04:05Z07:00"
RFC3339Nano"2006-01-02T15:04:05.999999999Z07:00"
Allowed: RFC3339 , RFC3339Nano
Default: RFC3339
delimiter string
The separator used between cells. Default is a comma (,).
Default: ,
header boolean
If true, the results contain a header row.
Default: true
extern object
Represents a source from a single file
body object[]
List of Flux statements
imports object[]
A list of package imports
as object
A valid Flux identifier
path object
Expressions begin and end with double quote marks
type string
Type of AST node
name string
The name of the file.
package object
Defines a package identifier
name object
A valid Flux identifier
type string
Type of AST node
type string
Type of AST node
now string <date-time>
Specifies the time that should be reported as now in the query. Default is the server now time.
params object

Key-value pairs passed as parameters during query execution.

To use parameters in your query, pass a query with params references (in dot notation)–for example:

  query: "from(bucket: params.mybucket)\
              |> range(start: params.rangeStart) |> limit(n:1)"

and pass params with the key-value pairs–for example:

  params: {
    "mybucket": "environment",
    "rangeStart": "-30d"
  }

During query execution, InfluxDB passes params to your script and substitutes the values.

Limitations

  • If you use params, you can’t use extern.
query required string
The query script to execute.
type string
The type of query. Must be “flux”.
Allowed: flux
Example request Ask AI about this
curl --request POST \
  "http://localhost:8086/api/v2/query" \
  --header "Authorization: Bearer INFLUX_TOKEN" \
  --header "Content-Type: application/json" \
  --data-raw '{
  "dialect": {
    "annotations": [
      "group"
    ],
    "commentPrefix": "#",
    "dateTimeFormat": "RFC3339",
    "delimiter": ",",
    "header": true
  },
  "extern": {
    "body": [
      {}
    ],
    "imports": [
      {}
    ],
    "name": "NAME",
    "package": {
      "name": {},
      "type": "TYPE"
    },
    "type": "TYPE"
  },
  "now": "NOW",
  "params": {},
  "query": "QUERY",
  "type": "flux"
}'

Responses

200 Success. The response body contains query results.
400

Bad request. The response body contains detail about the error.

InfluxDB OSS

  • Returns this error if the org parameter or orgID parameter doesn’t match an organization.
code required string
code is the machine-readable error code.
Allowed: internal error , not implemented , not found , conflict , invalid , unprocessable entity , empty value , unavailable , forbidden , too many requests , unauthorized , method not allowed , request too large , unsupported media type
err string
Stack of errors that occurred during processing of the request. Useful for debugging.
message string
Human-readable message.
op string
Describes the logical code operation when the error occurred. Useful for debugging.
401

Unauthorized. The error may indicate one of the following:

  • The Authorization: Token header is missing or malformed.
  • The API token value is missing from the header.
  • The token doesn’t have sufficient permissions to write to this organization and bucket.
code string
The HTTP status code description. Default is unauthorized.
Allowed: unauthorized
message string
A human-readable message that may contain detail about the error.
404

Not found. A requested resource was not found. The response body contains the requested resource type and the name value (if you passed it)–for example:

  • "organization name \"my-org\" not found"
  • "organization not found": indicates you passed an ID that did not match an organization.
code required string
code is the machine-readable error code.
Allowed: internal error , not implemented , not found , conflict , invalid , unprocessable entity , empty value , unavailable , forbidden , too many requests , unauthorized , method not allowed , request too large , unsupported media type
err string
Stack of errors that occurred during processing of the request. Useful for debugging.
message string
Human-readable message.
op string
Describes the logical code operation when the error occurred. Useful for debugging.
429

InfluxDB Cloud:

  • returns this error if a read or write request exceeds your plan’s adjustable service quotas or if a delete request exceeds the maximum global limit
  • returns Retry-After header that describes when to try the write again.

InfluxDB OSS:

  • doesn’t return this error.
500 Internal server error. The server encountered an unexpected situation.
code required string
code is the machine-readable error code.
Allowed: internal error , not implemented , not found , conflict , invalid , unprocessable entity , empty value , unavailable , forbidden , too many requests , unauthorized , method not allowed , request too large , unsupported media type
err string
Stack of errors that occurred during processing of the request. Useful for debugging.
message string
Human-readable message.
op string
Describes the logical code operation when the error occurred. Useful for debugging.
default Non 2XX error response from server.
code required string
code is the machine-readable error code.
Allowed: internal error , not implemented , not found , conflict , invalid , unprocessable entity , empty value , unavailable , forbidden , too many requests , unauthorized , method not allowed , request too large , unsupported media type
err string
Stack of errors that occurred during processing of the request. Useful for debugging.
message string
Human-readable message.
op string
Describes the logical code operation when the error occurred. Useful for debugging.
POST /api/v2/query/analyze

Analyze a Flux query

Analyzes a Flux query for syntax errors and returns the list of errors.

In the following sample query, from() is missing the property key.

```json
{ "query": "from(: \"iot_center\")\
            |> range(start: -90d)\
            |> filter(fn: (r) => r._measurement == \"environment\")",
  "type": "flux"
}
```

If you pass this in a request to the /api/v2/analyze endpoint, InfluxDB returns an errors list that contains an error object for the missing key.

Limitations

  • The endpoint doesn’t validate values in the query–for example:

  • The following sample query has correct syntax, but contains an incorrect from() property key:

    { "query": "from(foo: \"iot_center\")\
                |> range(start: -90d)\
                |> filter(fn: (r) => r._measurement == \"environment\")",
      "type": "flux"
    }

    If you pass this in a request to the /api/v2/analyze endpoint, InfluxDB returns an empty errors list.

Parameters

Header parameters
Zap-Trace-Span string
OpenTracing span context
Content-Type string
Allowed values: application/json

Request body

Flux query to analyze
Content-Type: application/json
dialect object

Options for tabular data output. Default output is annotated CSV with headers.

For more information about tabular data dialect, see W3 metadata vocabulary for tabular data.

annotations string[]

Annotation rows to include in the results. An annotation is metadata associated with an object (column) in the data model.

For more information about annotations in tabular data, see W3 metadata vocabulary for tabular data.

commentPrefix string
The character prefixed to comment strings. Default is a number sign (#).
Default: #
dateTimeFormat string

The format for timestamps in results. Default is RFC3339 date/time format. To include nanoseconds in timestamps, use RFC3339Nano.

Example formatted date/time values

FormatValue
RFC3339"2006-01-02T15:04:05Z07:00"
RFC3339Nano"2006-01-02T15:04:05.999999999Z07:00"
Allowed: RFC3339 , RFC3339Nano
Default: RFC3339
delimiter string
The separator used between cells. Default is a comma (,).
Default: ,
header boolean
If true, the results contain a header row.
Default: true
extern object
Represents a source from a single file
body object[]
List of Flux statements
imports object[]
A list of package imports
as object
A valid Flux identifier
path object
Expressions begin and end with double quote marks
type string
Type of AST node
name string
The name of the file.
package object
Defines a package identifier
name object
A valid Flux identifier
type string
Type of AST node
type string
Type of AST node
now string <date-time>
Specifies the time that should be reported as now in the query. Default is the server now time.
params object

Key-value pairs passed as parameters during query execution.

To use parameters in your query, pass a query with params references (in dot notation)–for example:

  query: "from(bucket: params.mybucket)\
              |> range(start: params.rangeStart) |> limit(n:1)"

and pass params with the key-value pairs–for example:

  params: {
    "mybucket": "environment",
    "rangeStart": "-30d"
  }

During query execution, InfluxDB passes params to your script and substitutes the values.

Limitations

  • If you use params, you can’t use extern.
query required string
The query script to execute.
type string
The type of query. Must be “flux”.
Allowed: flux
Example request Ask AI about this
curl --request POST \
  "http://localhost:8086/api/v2/query/analyze" \
  --header "Authorization: Bearer INFLUX_TOKEN" \
  --header "Content-Type: application/json" \
  --data-raw '{
  "dialect": {
    "annotations": [
      "group"
    ],
    "commentPrefix": "#",
    "dateTimeFormat": "RFC3339",
    "delimiter": ",",
    "header": true
  },
  "extern": {
    "body": [
      {}
    ],
    "imports": [
      {}
    ],
    "name": "NAME",
    "package": {
      "name": {},
      "type": "TYPE"
    },
    "type": "TYPE"
  },
  "now": "NOW",
  "params": {},
  "query": "QUERY",
  "type": "flux"
}'

Responses

200 Success. The response body contains the list of errors. If the query syntax is valid, the endpoint returns an empty errors list.
errors object[]
character integer
column integer
line integer
message string
400 Bad request. InfluxDB is unable to parse the request. The response body contains detail about the problem.
code required string
code is the machine-readable error code.
Allowed: internal error , not implemented , not found , conflict , invalid , unprocessable entity , empty value , unavailable , forbidden , too many requests , unauthorized , method not allowed , request too large , unsupported media type
err string
Stack of errors that occurred during processing of the request. Useful for debugging.
message string
Human-readable message.
op string
Describes the logical code operation when the error occurred. Useful for debugging.
default Internal server error
code required string
code is the machine-readable error code.
Allowed: internal error , not implemented , not found , conflict , invalid , unprocessable entity , empty value , unavailable , forbidden , too many requests , unauthorized , method not allowed , request too large , unsupported media type
err string
Stack of errors that occurred during processing of the request. Useful for debugging.
message string
Human-readable message.
op string
Describes the logical code operation when the error occurred. Useful for debugging.
POST /api/v2/query/ast

Generate a query Abstract Syntax Tree (AST)

Analyzes a Flux query and returns a complete package source Abstract Syntax Tree (AST) for the query.

Use this endpoint for deep query analysis such as debugging unexpected query results.

A Flux query AST provides a semantic, tree-like representation with contextual information about the query. The AST illustrates how the query is distributed into different components for execution.

Limitations

  • The endpoint doesn’t validate values in the query–for example:

    The following sample Flux query has correct syntax, but contains an incorrect from() property key:

    from(foo: "iot_center")
        |> range(start: -90d)
        |> filter(fn: (r) => r._measurement == "environment")

    The following sample JSON shows how to pass the query in the request body:

    from(foo: "iot_center")
    |> range(start: -90d)
    |> filter(fn: (r) => r._measurement == "environment")

    The following code sample shows how to pass the query as JSON in the request body:

    { "query": "from(foo: \"iot_center\")\
                    |> range(start: -90d)\
                    |> filter(fn: (r) => r._measurement == \"environment\")"
    }

    Passing this to /api/v2/query/ast will return a successful response with a generated AST.

Parameters

Header parameters
Zap-Trace-Span string
OpenTracing span context
Content-Type string
Allowed values: application/json

Request body

The Flux query to analyze.
Content-Type: application/json
query required string
The Flux query script to be analyzed.
Example request Ask AI about this
curl --request POST \
  "http://localhost:8086/api/v2/query/ast" \
  --header "Authorization: Bearer INFLUX_TOKEN" \
  --header "Content-Type: application/json" \
  --data-raw '{
  "query": "QUERY"
}'

Responses

200 Success. The response body contains an Abstract Syntax Tree (AST) of the Flux query.
ast object
Represents a complete package source tree.
files object[]
Package files
body object[]
List of Flux statements
imports object[]
A list of package imports
name string
The name of the file.
package object
Defines a package identifier
type string
Type of AST node
package string
Package name
path string
Package import path
type string
Type of AST node
400 Bad request. InfluxDB is unable to parse the request. The response body contains detail about the problem.
code required string
code is the machine-readable error code.
Allowed: internal error , not implemented , not found , conflict , invalid , unprocessable entity , empty value , unavailable , forbidden , too many requests , unauthorized , method not allowed , request too large , unsupported media type
err string
Stack of errors that occurred during processing of the request. Useful for debugging.
message string
Human-readable message.
op string
Describes the logical code operation when the error occurred. Useful for debugging.
default Internal server error.
code required string
code is the machine-readable error code.
Allowed: internal error , not implemented , not found , conflict , invalid , unprocessable entity , empty value , unavailable , forbidden , too many requests , unauthorized , method not allowed , request too large , unsupported media type
err string
Stack of errors that occurred during processing of the request. Useful for debugging.
message string
Human-readable message.
op string
Describes the logical code operation when the error occurred. Useful for debugging.
GET /api/v2/query/suggestions

List Flux query suggestions

Lists Flux query suggestions. Each suggestion contains a Flux function name and parameters.

Use this endpoint to retrieve a list of Flux query suggestions used in the InfluxDB Flux Query Builder.

Limitations

  • When writing a query, avoid using _functionName() helper functions exposed by this endpoint. Helper function names have an underscore (_) prefix and aren’t meant to be used directly in queries–for example:

    • To sort on a column and keep the top n records, use the top(n, columns=["_value"], tables=<-) function instead of the _sortLimit helper function. top uses _sortLimit.

Parameters

Header parameters
Zap-Trace-Span string
OpenTracing span context
Example request Ask AI about this
curl --request GET \
  "http://localhost:8086/api/v2/query/suggestions" \
  --header "Authorization: Bearer INFLUX_TOKEN"

Responses

200 Success. The response body contains a list of Flux query suggestions–function names used in the Flux Query Builder autocomplete suggestions.
funcs object[]
name string
params object
301 Moved Permanently. InfluxData has moved the URL of the endpoint. Use /api/v2/query/suggestions (without a trailing slash).
default Internal server error.
code required string
code is the machine-readable error code.
Allowed: internal error , not implemented , not found , conflict , invalid , unprocessable entity , empty value , unavailable , forbidden , too many requests , unauthorized , method not allowed , request too large , unsupported media type
err string
Stack of errors that occurred during processing of the request. Useful for debugging.
message string
Human-readable message.
op string
Describes the logical code operation when the error occurred. Useful for debugging.
GET /api/v2/query/suggestions/{name}

Retrieve a query suggestion for a branching suggestion

Retrieves a query suggestion that contains the name and parameters of the requested function.

Use this endpoint to pass a branching suggestion (a Flux function name) and retrieve the parameters of the requested function.

Limitations

  • Use /api/v2/query/suggestions/{name} (without a trailing slash). /api/v2/query/suggestions/{name}/ (note the trailing slash) results in a HTTP 301 Moved Permanently status.

  • The function name must exist and must be spelled correctly.

Parameters

Path parameters
name required string
Header parameters
Zap-Trace-Span string
OpenTracing span context
Example request Ask AI about this
curl --request GET \
  "http://localhost:8086/api/v2/query/suggestions/{name}" \
  --header "Authorization: Bearer INFLUX_TOKEN"

Responses

200 Success. The response body contains the function name and parameters.
name string
params object
500 Internal server error. The value passed for name may have been misspelled.
code required string
code is the machine-readable error code.
Allowed: internal error , not implemented , not found , conflict , invalid , unprocessable entity , empty value , unavailable , forbidden , too many requests , unauthorized , method not allowed , request too large , unsupported media type
err string
Stack of errors that occurred during processing of the request. Useful for debugging.
message string
Human-readable message.
op string
Describes the logical code operation when the error occurred. Useful for debugging.

Was this page helpful?

Thank you for your feedback!