Query data
/api/v2/queryQuery 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.
Related guides
Parameters
Query parameters
org
stringAn organization name or ID.
InfluxDB Cloud
- Doesn’t use the
orgparameter ororgIDparameter. - Queries the bucket in the organization associated with the authorization (API token).
InfluxDB OSS v2
- Requires either the
orgparameter ororgIDparameter. - Queries the bucket in the specified organization.
orgID
stringAn organization ID.
InfluxDB Cloud
- Doesn’t use the
orgparameter ororgIDparameter. - Queries the bucket in the organization associated with the authorization (API token).
InfluxDB OSS v2
- Requires either the
orgparameter ororgIDparameter. - Queries the bucket in the specified organization.
Header parameters
Zap-Trace-Span
stringAccept-Encoding
stringgzip
, identityidentityContent-Type
stringapplication/json
, application/vnd.fluxRequest body
application/jsondialect
stringextern
stringnow
string <date-time>now in the query.
Default is the server now time.query
required
stringtype
stringfluxcurl --request POST \
"http://localhost:8086/api/v2/query" \
--header "Authorization: Bearer INFLUX_TOKEN" \
--header "Content-Type: application/json" \
--data-raw '{
"dialect": {},
"extern": {},
"now": "NOW",
"query": "QUERY",
"type": "flux"
}'Responses
Bad request. The response body contains detail about the error.
InfluxDB OSS v2
- Returns this error if the
orgparameter ororgIDparameter doesn’t match an organization.
code
required
stringinternal 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 typeerr
stringmessage
stringop
stringUnauthorized. The error may indicate one of the following:
- The
Authorization: Tokenheader 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
stringunauthorized.unauthorizedmessage
stringNot 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
stringinternal 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 typeerr
stringmessage
stringop
stringInfluxDB 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-Afterheader that describes when to try the write again.
InfluxDB OSS v2:
- doesn’t return this error.
code
required
stringinternal 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 typeerr
stringmessage
stringop
stringcode
required
stringinternal 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 typeerr
stringmessage
stringop
string/api/v2/query/analyzeAnalyze 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/analyzeendpoint, InfluxDB returns an emptyerrorslist.
Parameters
Header parameters
Zap-Trace-Span
stringContent-Type
stringapplication/jsonRequest body
application/jsondialect
stringextern
stringnow
string <date-time>now in the query.
Default is the server now time.query
required
stringtype
stringfluxcurl --request POST \
"http://localhost:8086/api/v2/query/analyze" \
--header "Authorization: Bearer INFLUX_TOKEN" \
--header "Content-Type: application/json" \
--data-raw '{
"dialect": {},
"extern": {},
"now": "NOW",
"query": "QUERY",
"type": "flux"
}'Responses
errors.
If the query syntax is valid, the endpoint returns an empty errors list.errors
object[]character
integercolumn
integerline
integermessage
stringcode
required
stringinternal 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 typeerr
stringmessage
stringop
stringcode
required
stringinternal 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 typeerr
stringmessage
stringop
string/api/v2/query/astGenerate 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/astwill return a successful response with a generated AST.
Parameters
Header parameters
Zap-Trace-Span
stringContent-Type
stringapplication/jsonRequest body
application/jsonquery
required
stringcurl --request POST \
"http://localhost:8086/api/v2/query/ast" \
--header "Authorization: Bearer INFLUX_TOKEN" \
--header "Content-Type: application/json" \
--data-raw '{
"query": "QUERY"
}'Responses
ast
stringcode
required
stringinternal 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 typeerr
stringmessage
stringop
stringcode
required
stringinternal 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 typeerr
stringmessage
stringop
string/api/v2/query/suggestionsList 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_sortLimithelper function.topuses_sortLimit.
- To sort on a column and keep the top n records, use the
Related Guides
Parameters
Header parameters
Zap-Trace-Span
stringcurl --request GET \
"http://localhost:8086/api/v2/query/suggestions" \
--header "Authorization: Bearer INFLUX_TOKEN"Responses
funcs
object[]/api/v2/query/suggestions (without a trailing slash).code
required
stringinternal 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 typeerr
stringmessage
stringop
string/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 HTTP301 Moved Permanentlystatus.The function
namemust exist and must be spelled correctly.
Related Guides
Parameters
Path parameters
name
required
stringHeader parameters
Zap-Trace-Span
stringcurl --request GET \
"http://localhost:8086/api/v2/query/suggestions/{name}" \
--header "Authorization: Bearer INFLUX_TOKEN"Responses
name
stringparams
objectname may have been misspelled.code
required
stringinternal 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 typeerr
stringmessage
stringop
stringWas this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, use the following resources:
Customers with an annual or support contract can contact InfluxData Support.