InfluxData Query API

Retrieve data, analyze queries, and get query suggestions.

OpenAPI Specification

influxdata-query-api-openapi.yml Raw ↑
openapi: 3.0.0
info:
  title: InfluxDB Cloud API Service Authorizations (API tokens) Authorizations (API tokens) Query API
  version: 2.0.1
  description: 'The InfluxDB v2 API provides a programmatic interface for all interactions with InfluxDB. Access the InfluxDB API using the `/api/v2/` endpoint.

    '
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
servers:
- url: /api/v2
security:
- TokenAuthentication: []
tags:
- name: Query
  description: 'Retrieve data, analyze queries, and get query suggestions.

    '
paths:
  /query/ast:
    post:
      operationId: PostQueryAst
      tags:
      - Query
      summary: Generate a query Abstract Syntax Tree (AST)
      description: "Analyzes a Flux query and returns a complete package source [Abstract Syntax\nTree (AST)](https://docs.influxdata.com/influxdb/cloud/reference/glossary/#abstract-syntax-tree-ast)\nfor the query.\n\nUse this endpoint for deep query analysis such as debugging unexpected query\nresults.\n\nA Flux query AST provides a semantic, tree-like representation with contextual\ninformation about the query. The AST illustrates how the query is distributed\ninto different components for execution.\n\n#### Limitations\n\n-  The endpoint doesn't validate values in the query--for example:\n\n    The following sample Flux query has correct syntax, but contains an incorrect `from()` property key:\n\n    ```js\n    from(foo: \"iot_center\")\n        |> range(start: -90d)\n        |> filter(fn: (r) => r._measurement == \"environment\")\n    ```\n\n    The following sample JSON shows how to pass the query in the request body:\n\n    ```js\n    from(foo: \"iot_center\")\n    |> range(start: -90d)\n    |> filter(fn: (r) => r._measurement == \"environment\")\n    ```\n\n    The following code sample shows how to pass the query as JSON in the request body:\n\n    ```json\n    { \"query\": \"from(foo: \\\"iot_center\\\")\\\n                    |> range(start: -90d)\\\n                    |> filter(fn: (r) => r._measurement == \\\"environment\\\")\"\n    }\n    ```\n\n    Passing this to `/api/v2/query/ast` will return a successful response\n    with a generated AST.\n"
      parameters:
      - $ref: '#/components/parameters/TraceSpan'
      - in: header
        name: Content-Type
        schema:
          type: string
          enum:
          - application/json
      requestBody:
        description: The Flux query to analyze.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LanguageRequest'
      x-codeSamples:
      - lang: Shell
        label: 'cURL: Analyze and generate AST for the query'
        source: "curl --request POST \"http://localhost:8086/api/v2/query/ast\" \\\n  --header 'Content-Type: application/json' \\\n  --header 'Accept: application/json' \\\n  --header \"Authorization: Token INFLUX_TOKEN\" \\\n  --data-binary @- << EOL\n      {\n        \"query\": \"from(bucket: \\\"INFLUX_BUCKET_NAME\\\")\\\n        |> range(start: -5m)\\\n        |> filter(fn: (r) => r._measurement == \\\"example-measurement\\\")\"\n      }\nEOL\n"
      responses:
        '200':
          description: 'Success.

            The response body contains an Abstract Syntax Tree (AST) of the Flux query.

            '
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ASTResponse'
              examples:
                successResponse:
                  value:
                    ast:
                      type: Package
                      package: main
                      files:
                      - type: File
                        location:
                          start:
                            line: 1
                            column: 1
                          end:
                            line: 1
                            column: 109
                          source: 'from(bucket: "example-bucket") |> range(start: -5m) |> filter(fn: (r) => r._measurement == "example-measurement")'
                        metadata: parser-type=rust
                        package: null
                        imports: null
                        body:
                        - type: ExpressionStatement
                          location:
                            start:
                              line: 1
                              column: 1
                            end:
                              line: 1
                              column: 109
                            source: 'from(bucket: "example-bucket") |> range(start: -5m) |> filter(fn: (r) => r._measurement == "example-measurement")'
                          expression:
                            type: PipeExpression
                            location:
                              start:
                                line: 1
                                column: 1
                              end:
                                line: 1
                                column: 109
                              source: 'from(bucket: "example-bucket") |> range(start: -5m) |> filter(fn: (r) => r._measurement == "example-measurement")'
                            argument:
                              type: PipeExpression
                              location:
                                start:
                                  line: 1
                                  column: 1
                                end:
                                  line: 1
                                  column: 47
                                source: 'from(bucket: "example-bucket") |> range(start: -5m)'
                              argument:
                                type: CallExpression
                                location:
                                  start:
                                    line: 1
                                    column: 1
                                  end:
                                    line: 1
                                    column: 26
                                  source: 'from(bucket: "example-bucket")'
                                callee:
                                  type: Identifier
                                  location:
                                    start:
                                      line: 1
                                      column: 1
                                    end:
                                      line: 1
                                      column: 5
                                    source: from
                                  name: from
                                arguments:
                                - type: ObjectExpression
                                  location:
                                    start:
                                      line: 1
                                      column: 6
                                    end:
                                      line: 1
                                      column: 25
                                    source: 'bucket: "example-bucket"'
                                  properties:
                                  - type: Property
                                    location:
                                      start:
                                        line: 1
                                        column: 6
                                      end:
                                        line: 1
                                        column: 25
                                      source: 'bucket: "example-bucket"'
                                    key:
                                      type: Identifier
                                      location:
                                        start:
                                          line: 1
                                          column: 6
                                        end:
                                          line: 1
                                          column: 12
                                        source: bucket
                                      name: bucket
                                    value:
                                      type: StringLiteral
                                      location:
                                        start:
                                          line: 1
                                          column: 14
                                        end:
                                          line: 1
                                          column: 25
                                        source: '"example-bucket"'
                                      value: example-bucket
                              call:
                                type: CallExpression
                                location:
                                  start:
                                    line: 1
                                    column: 30
                                  end:
                                    line: 1
                                    column: 47
                                  source: 'range(start: -5m)'
                                callee:
                                  type: Identifier
                                  location:
                                    start:
                                      line: 1
                                      column: 30
                                    end:
                                      line: 1
                                      column: 35
                                    source: range
                                  name: range
                                arguments:
                                - type: ObjectExpression
                                  location:
                                    start:
                                      line: 1
                                      column: 36
                                    end:
                                      line: 1
                                      column: 46
                                    source: 'start: -5m'
                                  properties:
                                  - type: Property
                                    location:
                                      start:
                                        line: 1
                                        column: 36
                                      end:
                                        line: 1
                                        column: 46
                                      source: 'start: -5m'
                                    key:
                                      type: Identifier
                                      location:
                                        start:
                                          line: 1
                                          column: 36
                                        end:
                                          line: 1
                                          column: 41
                                        source: start
                                      name: start
                                    value:
                                      type: UnaryExpression
                                      location:
                                        start:
                                          line: 1
                                          column: 43
                                        end:
                                          line: 1
                                          column: 46
                                        source: -5m
                                      operator: '-'
                                      argument:
                                        type: DurationLiteral
                                        location:
                                          start:
                                            line: 1
                                            column: 44
                                          end:
                                            line: 1
                                            column: 46
                                          source: 5m
                                        values:
                                        - magnitude: 5
                                          unit: m
                            call:
                              type: CallExpression
                              location:
                                start:
                                  line: 1
                                  column: 51
                                end:
                                  line: 1
                                  column: 109
                                source: 'filter(fn: (r) => r._measurement == "example-measurement")'
                              callee:
                                type: Identifier
                                location:
                                  start:
                                    line: 1
                                    column: 51
                                  end:
                                    line: 1
                                    column: 57
                                  source: filter
                                name: filter
                              arguments:
                              - type: ObjectExpression
                                location:
                                  start:
                                    line: 1
                                    column: 58
                                  end:
                                    line: 1
                                    column: 108
                                  source: 'fn: (r) => r._measurement == "example-measurement"'
                                properties:
                                - type: Property
                                  location:
                                    start:
                                      line: 1
                                      column: 58
                                    end:
                                      line: 1
                                      column: 108
                                    source: 'fn: (r) => r._measurement == "example-measurement"'
                                  key:
                                    type: Identifier
                                    location:
                                      start:
                                        line: 1
                                        column: 58
                                      end:
                                        line: 1
                                        column: 60
                                      source: fn
                                    name: fn
                                  value:
                                    type: FunctionExpression
                                    location:
                                      start:
                                        line: 1
                                        column: 62
                                      end:
                                        line: 1
                                        column: 108
                                      source: (r) => r._measurement == "example-measurement"
                                    params:
                                    - type: Property
                                      location:
                                        start:
                                          line: 1
                                          column: 63
                                        end:
                                          line: 1
                                          column: 64
                                        source: r
                                      key:
                                        type: Identifier
                                        location:
                                          start:
                                            line: 1
                                            column: 63
                                          end:
                                            line: 1
                                            column: 64
                                          source: r
                                        name: r
                                      value: null
                                    body:
                                      type: BinaryExpression
                                      location:
                                        start:
                                          line: 1
                                          column: 69
                                        end:
                                          line: 1
                                          column: 108
                                        source: r._measurement == "example-measurement"
                                      operator: ==
                                      left:
                                        type: MemberExpression
                                        location:
                                          start:
                                            line: 1
                                            column: 69
                                          end:
                                            line: 1
                                            column: 83
                                          source: r._measurement
                                        object:
                                          type: Identifier
                                          location:
                                            start:
                                              line: 1
                                              column: 69
                                            end:
                                              line: 1
                                              column: 70
                                            source: r
                                          name: r
                                        property:
                                          type: Identifier
                                          location:
                                            start:
                                              line: 1
                                              column: 71
                                            end:
                                              line: 1
                                              column: 83
                                            source: _measurement
                                          name: _measurement
                                      right:
                                        type: StringLiteral
                                        location:
                                          start:
                                            line: 1
                                            column: 87
                                          end:
                                            line: 1
                                            column: 108
                                          source: '"example-measurement"'
                                        value: example-measurement
        '400':
          description: 'Bad request.

            InfluxDB is unable to parse the request.

            The response body contains detail about the problem.

            '
          headers:
            X-Platform-Error-Code:
              description: 'The reason for the error.

                '
              schema:
                type: string
                example: invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                invalidASTValue:
                  summary: Invalid AST
                  description: 'If the request body contains a missing property key in `from()`,

                    returns `invalid` and problem detail.

                    '
                  value:
                    code: invalid
                    message: 'invalid AST: loc 1:6-1:19: missing property key'
        default:
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /query/suggestions:
    get:
      operationId: GetQuerySuggestions
      tags:
      - Query
      summary: List Flux query suggestions
      description: "Lists Flux query suggestions. Each suggestion contains a\n[Flux function](https://docs.influxdata.com/flux/v0.x/stdlib/all-functions/)\nname and parameters.\n\nUse this endpoint to retrieve a list of Flux query suggestions used in the\nInfluxDB Flux Query Builder.\n\n#### Limitations\n\n- When writing a query, avoid using `_functionName()` helper functions\nexposed by this endpoint.  Helper function names have an underscore (`_`)\nprefix and aren't meant to be used directly in queries--for example:\n\n  - To sort on a column and keep the top n records, use the\n    `top(n, columns=[\"_value\"], tables=<-)` function instead of the `_sortLimit`\n    helper function. `top` uses `_sortLimit`.\n\n#### Related Guides\n\n- [List of all Flux functions](https://docs.influxdata.com/flux/v0.x/stdlib/all-functions/)\n"
      parameters:
      - $ref: '#/components/parameters/TraceSpan'
      responses:
        '200':
          description: 'Success.

            The response body contains a list of Flux query suggestions--function

            names used in the Flux Query Builder autocomplete suggestions.

            '
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FluxSuggestions'
              examples:
                successResponse:
                  value:
                    funcs:
                    - name: _fillEmpty
                      params:
                        createEmpty: bool
                        tables: stream
                    - name: _highestOrLowest
                      params:
                        _sortLimit: function
                        column: invalid
                        groupColumns: array
                        n: invalid
                        reducer: function
                        tables: stream
                    - name: _hourSelection
                      params:
                        location: object
                        start: int
                        stop: int
                        tables: stream
                        timeColumn: string
                    - name: _sortLimit
                      params:
                        columns: array
                        desc: bool
                        n: int
                        tables: stream
                    - name: _window
                      params:
                        createEmpty: bool
                        every: duration
                        location: object
                        offset: duration
                        period: duration
                        startColumn: string
                        stopColumn: string
                        tables: stream
                        timeColumn: string
                    - name: aggregateWindow
                      params:
                        column: invalid
                        createEmpty: bool
                        every: duration
                        fn: function
                        location: object
                        offset: duration
                        period: duration
                        tables: stream
                        timeDst: string
                        timeSrc: string
                    - name: bool
                      params:
                        v: invalid
                    - name: bottom
                      params:
                        columns: array
                        n: int
                        tables: stream
                    - name: buckets
                      params:
                        host: string
                        org: string
                        orgID: string
                        token: string
                    - name: bytes
                      params:
                        v: invalid
                    - name: cardinality
                      params:
                        bucket: string
                        bucketID: string
                        host: string
                        org: string
                        orgID: string
                        predicate: function
                        start: invalid
                        stop: invalid
                        token: string
                    - name: chandeMomentumOscillator
                      params:
                        columns: array
                        n: int
                        tables: stream
                    - name: columns
                      params:
                        column: string
                        tables: stream
                    - name: contains
                      params:
                        set: array
                        value: invalid
                    - name: count
                      params:
                        column: string
                        tables: stream
                    - name: cov
                      params:
                        'on': array
                        pearsonr: bool
                        x: invalid
                        y: invalid
                    - name: covariance
                      params:
                        columns: array
                        pearsonr: bool
                        tables: stream
                        valueDst: string
                    - name: cumulativeSum
                      params:
                        columns: array
                        tables: stream
                    - name: derivative
                      params:
                        columns: array
                        initialZero: bool
                        nonNegative: bool
                        tables: stream
                        timeColumn: string
                        unit: duration
                    - name: die
                      params:
                        msg: string
                    - name: difference
                      params:
                        columns: array
                        initialZero: bool
                        keepFirst: bool
                        nonNegative: bool
                        tables: stream
                    - name: display
                      params:
                        v: invalid
                    - name: distinct
                      params:
                        column: string
                        tables: stream
                    - name: doubleEMA
                      params:
                        n: int
                        tables: stream
                    - name: drop
                      params:
                        columns: array
                        fn: function
                        tables: stream
                    - name: duplicate
                      params:
                        as: string
                        column: string
                        tables: stream
                    - name: duration
                      params:
                        v: invalid
                    - name: elapsed
                      params:
                        columnName: string
                        tables: stream
                        timeColumn: string
                        unit: duration
                    - name: exponentialMovingAverage
                      params:
                        n: int
                        tables: stream
                    - name: fill
                      params:
                        column: string
                        tables: stream
                        usePrevious: bool
                        value: invalid
                    - name: filter
                      params:
                        fn: function
                        onEmpty: string
                        tables: stream
                    - name: findColumn
                      params:
                        column: string
                        fn: function
                        tables: stream
                    - name: findRecord
                      params:
                        fn: function
                        idx: int
                        tables: stream
                    - name: first
                      params:
                        column: string
                        tables: stream
                    - name: float
                      params:
                        v: invalid
                    - name: from
                      params:
                        bucket: string
                        bucketID: string
                        host: string
                        org: string
                        orgID: string
                        token: string
                    - name: getColumn
                      params:
                        column: string
                    - name: getRecord
                      params:
                        idx: int
                    - name: group
                      params:
                        columns: array
                        mode: string
                        tables: stream
                    - name: highestAverage
                      params:
                        column: string
                        groupColumns: array
                        n: int
                        tables: stream
                    - name: highestCurrent
                      params:
                        column: string
                        groupColumns: array
                        n: int
                        tables: stream
                    - name: highestMax
                      params:
                        column: string
                        groupColumns: array
                        n: int
                        tables: stream
                    - name: histogram
                      params:
                        bins: array
                        column: string
                        countColumn: string
                        normalize: bool
                        tables: stream
                        upperBoundColumn: string
                    - name: histogramQuantile
                      params:
                        countColumn: string
                        minValue: float
                        quantile: float
                        tables: stream
                        upperBoundColumn: string
                        valueColumn: string
                    - name: holtWinters
                      params:
                        column: string
                        interval: duration
                        n: int
                        seasonality: int
                        tables: stream
                        timeColumn: string
                        withFit: bool
                    - name: hourSelection
                      params:
                        location: object
                        start: int
                        stop: int
                        tables: stream
                        timeColumn: string
                    - name: increase
                      params:
                        columns: array
                        tables: stream
                    - name: int
                      params:
                        v: invalid
                    - name: integral
                      params:
                        column: string
                        interpolate: string
                        tables: stream
                        timeColumn: string
                        unit: duration
                    - name: join
                      params:
                        method: string
                        'on': array
                        tables: invalid
                    - name: kaufmansAMA
                      params:
                        column: string
                        n: int
                        tables: stream
                    - name: kaufmansER
                      params:
                        n: int
                        tables: stream
                    - name: ke

# --- truncated at 32 KB (83 KB total) ---
# Full source: https://raw.githubusercontent.com/api-evangelist/influxdata/refs/heads/main/openapi/influxdata-query-api-openapi.yml