chore(v2): OSS v2 query API: add, fix, cleanup:
- Adds missing examples for v1-compatible /query - Fixes curl params in examples - Removes unsupported async option from examples - Updates terms for consistency with branding and influxdb3 docs - Copies the missing POST /query operation from swaggerv1compat to the v2 ref.yml - Effectively removes the separate v1-compat spec, and adds redirects and tags for v1-compat endpoints in v2/ref.yml - Updates affected linksapi-query-examples
parent
a424a92b72
commit
b8d4dfcc36
|
@ -10,7 +10,5 @@ apis:
|
|||
root: v2/ref.yml
|
||||
x-influxdata-docs-aliases:
|
||||
- /influxdb/v2/api/
|
||||
v1-compatibility@2:
|
||||
root: v1-compatibility/swaggerV1Compat.yml
|
||||
x-influxdata-docs-aliases:
|
||||
- /influxdb/v2/api/v1-compatibility/
|
||||
- /influxdb/v2/api/v1/
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
- Headers
|
||||
- Pagination
|
||||
- Response codes
|
||||
- Compatibility endpoints
|
||||
- name: All endpoints
|
||||
tags: []
|
||||
|
|
|
@ -58,6 +58,7 @@ tags:
|
|||
- [Manage API tokens](/influxdb/v2/security/tokens/)
|
||||
- [Assign a token to a specific user](/influxdb/v2/security/tokens/create-token/)
|
||||
name: Authorizations (API tokens)
|
||||
- name: Authorizations (v1-compatible)
|
||||
- name: Backup
|
||||
- description: |
|
||||
Store your data in InfluxDB [buckets](/influxdb/v2/reference/glossary/#bucket).
|
||||
|
@ -88,6 +89,15 @@ tags:
|
|||
| `orgID` | 16-byte string | The organization ID ([find your organization](/influxdb/v2/organizations/view-orgs/). |
|
||||
name: Common parameters
|
||||
x-traitTag: true
|
||||
- name: Compatibility endpoints
|
||||
description: |
|
||||
InfluxDB v2 provides a v1-compatible API for backward compatibility with InfluxDB 1.x clients and integrations.
|
||||
|
||||
Use these endpoints with InfluxDB 1.x client libraries and third-party integrations such as Grafana, Telegraf, and other tools designed for InfluxDB 1.x. The compatibility layer maps InfluxDB 1.x concepts (databases, retention policies) to InfluxDB v2 resources (buckets, organizations) through database retention policy (DBRP) mappings.
|
||||
|
||||
- [Write data (v1-compatible)](#tag/Write-data-(v1-compatible))
|
||||
- [Query data using InfluxQL (v1-compatible)](#tag/Query-data-(v1-compatible))
|
||||
- [Manage v1-compatible users and permissions](#tag/Authorizations-(v1-compatible))
|
||||
- name: Config
|
||||
- name: Dashboards
|
||||
- name: Data I/O endpoints
|
||||
|
@ -99,7 +109,7 @@ tags:
|
|||
databases and retention policies are mapped to buckets using the
|
||||
database and retention policy (DBRP) mapping service.
|
||||
The DBRP mapping service uses the database and retention policy
|
||||
specified in 1.x compatibility API requests to route operations to a bucket.
|
||||
specified in v1 compatibility API requests to route operations to a bucket.
|
||||
|
||||
### Related guides
|
||||
|
||||
|
@ -139,9 +149,6 @@ tags:
|
|||
x-traitTag: true
|
||||
- name: Health
|
||||
- name: Labels
|
||||
- name: Legacy Authorizations
|
||||
- name: Legacy Query
|
||||
- name: Legacy Write
|
||||
- name: Metrics
|
||||
- name: NotificationEndpoints
|
||||
- name: NotificationRules
|
||||
|
@ -194,6 +201,7 @@ tags:
|
|||
- description: |
|
||||
Retrieve data, analyze queries, and get query suggestions.
|
||||
name: Query
|
||||
- name: Query data (v1-compatible)
|
||||
- description: |
|
||||
See the [**API Quick Start**](/influxdb/v2/api-guide/api_intro/)
|
||||
to get up and running authenticating with tokens, writing to buckets, and querying data.
|
||||
|
@ -314,6 +322,7 @@ tags:
|
|||
- description: |
|
||||
Write time series data to [buckets](/influxdb/v2/reference/glossary/#bucket).
|
||||
name: Write
|
||||
- name: Write data (v1-compatible)
|
||||
paths:
|
||||
/api/v2:
|
||||
get:
|
||||
|
@ -12863,7 +12872,7 @@ paths:
|
|||
description: Unexpected error
|
||||
summary: List all legacy authorizations
|
||||
tags:
|
||||
- Legacy Authorizations
|
||||
- Authorizations (v1-compatible)
|
||||
post:
|
||||
description: |
|
||||
Creates a legacy authorization and returns the legacy authorization.
|
||||
|
@ -12926,7 +12935,7 @@ paths:
|
|||
description: Unexpected error
|
||||
summary: Create a legacy authorization
|
||||
tags:
|
||||
- Legacy Authorizations
|
||||
- Authorizations (v1-compatible)
|
||||
servers:
|
||||
- url: /private
|
||||
/legacy/authorizations/{authID}:
|
||||
|
@ -12948,7 +12957,7 @@ paths:
|
|||
description: Unexpected error
|
||||
summary: Delete a legacy authorization
|
||||
tags:
|
||||
- Legacy Authorizations
|
||||
- Authorizations (v1-compatible)
|
||||
get:
|
||||
operationId: GetLegacyAuthorizationsID
|
||||
parameters:
|
||||
|
@ -12971,7 +12980,7 @@ paths:
|
|||
description: Unexpected error
|
||||
summary: Retrieve a legacy authorization
|
||||
tags:
|
||||
- Legacy Authorizations
|
||||
- Authorizations (v1-compatible)
|
||||
patch:
|
||||
operationId: PatchLegacyAuthorizationsID
|
||||
parameters:
|
||||
|
@ -13001,7 +13010,7 @@ paths:
|
|||
description: Unexpected error
|
||||
summary: Update a legacy authorization to be active or inactive
|
||||
tags:
|
||||
- Legacy Authorizations
|
||||
- Authorizations (v1-compatible)
|
||||
servers:
|
||||
- url: /private
|
||||
/legacy/authorizations/{authID}/password:
|
||||
|
@ -13034,94 +13043,29 @@ paths:
|
|||
description: Unexpected error
|
||||
summary: Set a legacy authorization password
|
||||
tags:
|
||||
- Legacy Authorizations
|
||||
- Authorizations (v1-compatible)
|
||||
servers:
|
||||
- url: /private
|
||||
/query:
|
||||
get:
|
||||
description: Queries InfluxDB using InfluxQL.
|
||||
summary: Execute InfluxQL query (v1-compatible)
|
||||
description: |
|
||||
Executes an InfluxQL query to retrieve data from the specified database.
|
||||
|
||||
This endpoint is compatible with InfluxDB 1.x client libraries and third-party integrations such as Grafana.
|
||||
Use query parameters to specify the database and the InfluxQL query.
|
||||
operationId: GetLegacyQuery
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/TraceSpan'
|
||||
- in: header
|
||||
name: Accept
|
||||
schema:
|
||||
default: application/json
|
||||
description: |
|
||||
Media type that the client can understand.
|
||||
|
||||
**Note**: With `application/csv`, query results include [**unix timestamps**](/influxdb/v2/reference/glossary/#unix-timestamp) instead of [RFC3339 timestamps](/influxdb/v2/reference/glossary/#rfc3339-timestamp).
|
||||
enum:
|
||||
- application/json
|
||||
- application/csv
|
||||
- text/csv
|
||||
- application/x-msgpack
|
||||
type: string
|
||||
- description: The content encoding (usually a compression algorithm) that the client can understand.
|
||||
in: header
|
||||
name: Accept-Encoding
|
||||
schema:
|
||||
default: identity
|
||||
description: The content coding. Use `gzip` for compressed data or `identity` for unmodified, uncompressed data.
|
||||
enum:
|
||||
- gzip
|
||||
- identity
|
||||
type: string
|
||||
- in: header
|
||||
name: Content-Type
|
||||
schema:
|
||||
enum:
|
||||
- application/json
|
||||
type: string
|
||||
- description: The InfluxDB 1.x username to authenticate the request.
|
||||
in: query
|
||||
name: u
|
||||
schema:
|
||||
type: string
|
||||
- description: The InfluxDB 1.x password to authenticate the request.
|
||||
in: query
|
||||
name: p
|
||||
schema:
|
||||
type: string
|
||||
- description: |
|
||||
The database to query data from.
|
||||
This is mapped to an InfluxDB [bucket](/influxdb/v2/reference/glossary/#bucket).
|
||||
For more information, see [Database and retention policy mapping](/influxdb/v2/api/influxdb-1x/dbrp/).
|
||||
in: query
|
||||
name: db
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- description: |
|
||||
The retention policy to query data from.
|
||||
This is mapped to an InfluxDB [bucket](/influxdb/v2/reference/glossary/#bucket).
|
||||
For more information, see [Database and retention policy mapping](/influxdb/v2/api/influxdb-1x/dbrp/).
|
||||
in: query
|
||||
name: rp
|
||||
schema:
|
||||
type: string
|
||||
- description: The InfluxQL query to execute. To execute multiple queries, delimit queries with a semicolon (`;`).
|
||||
in: query
|
||||
name: q
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- description: |
|
||||
A unix timestamp precision.
|
||||
Formats timestamps as [unix (epoch) timestamps](/influxdb/v2/reference/glossary/#unix-timestamp) with the specified precision
|
||||
instead of [RFC3339 timestamps](/influxdb/v2/reference/glossary/#rfc3339-timestamp) with nanosecond precision.
|
||||
in: query
|
||||
name: epoch
|
||||
schema:
|
||||
enum:
|
||||
- ns
|
||||
- u
|
||||
- µ
|
||||
- ms
|
||||
- s
|
||||
- m
|
||||
- h
|
||||
type: string
|
||||
- $ref: '#/components/parameters/AuthV1Username'
|
||||
- $ref: '#/components/parameters/AuthV1Password'
|
||||
- $ref: '#/components/parameters/Accept'
|
||||
- $ref: '#/components/parameters/AcceptEncoding'
|
||||
- $ref: '#/components/parameters/Content-Type'
|
||||
- $ref: '#/components/parameters/V1Database'
|
||||
- $ref: '#/components/parameters/V1RetentionPolicy'
|
||||
- $ref: '#/components/parameters/V1Epoch'
|
||||
- $ref: '#/components/parameters/V1Query'
|
||||
responses:
|
||||
'200':
|
||||
content:
|
||||
|
@ -13185,9 +13129,85 @@ paths:
|
|||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
description: Error processing query
|
||||
summary: Query with the 1.x compatibility API
|
||||
tags:
|
||||
- Legacy Query
|
||||
- Query data (v1-compatible)
|
||||
post:
|
||||
operationId: PostQueryV1
|
||||
summary: Execute InfluxQL query (v1-compatible)
|
||||
description: |
|
||||
Executes an InfluxQL query to retrieve data from the specified database.
|
||||
|
||||
This endpoint is compatible with InfluxDB 1.x client libraries and third-party integrations such as Grafana.
|
||||
Use query parameters to specify the database and the InfluxQL query.
|
||||
tags:
|
||||
- Query data (v1-compatible)
|
||||
requestBody:
|
||||
description: InfluxQL query to execute.
|
||||
content:
|
||||
text/plain:
|
||||
schema:
|
||||
type: string
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/TraceSpan'
|
||||
- $ref: '#/components/parameters/AuthV1Username'
|
||||
- $ref: '#/components/parameters/AuthV1Password'
|
||||
- $ref: '#/components/parameters/Accept'
|
||||
- $ref: '#/components/parameters/AcceptEncoding'
|
||||
- $ref: '#/components/parameters/Content-Type'
|
||||
- $ref: '#/components/parameters/V1Database'
|
||||
- $ref: '#/components/parameters/V1RetentionPolicy'
|
||||
- $ref: '#/components/parameters/V1Epoch'
|
||||
responses:
|
||||
'200':
|
||||
description: Query results
|
||||
headers:
|
||||
Content-Encoding:
|
||||
description: The Content-Encoding entity header is used to compress the media-type. When present, its value indicates which encodings were applied to the entity-body
|
||||
schema:
|
||||
type: string
|
||||
description: Specifies that the response in the body is encoded with gzip or not encoded with identity.
|
||||
default: identity
|
||||
enum:
|
||||
- gzip
|
||||
- identity
|
||||
Trace-Id:
|
||||
description: The Trace-Id header reports the request's trace ID, if one was generated.
|
||||
schema:
|
||||
type: string
|
||||
description: Specifies the request's trace ID.
|
||||
content:
|
||||
application/csv:
|
||||
schema:
|
||||
$ref: '#/components/schemas/InfluxqlCsvResponse'
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/InfluxqlJsonResponse'
|
||||
text/csv:
|
||||
schema:
|
||||
$ref: '#/components/schemas/InfluxqlCsvResponse'
|
||||
examples:
|
||||
influxql-chunk_size_2:
|
||||
value: |
|
||||
{"results":[{"statement_id":0,"series":[{"name":"mymeas","columns":["time","myfield","mytag"],"values":[["2016-05-19T18:37:55Z",90,"1"],["2016-05-19T18:37:56Z",90,"1"]],"partial":true}],"partial":true}]}
|
||||
{"results":[{"statement_id":0,"series":[{"name":"mymeas","columns":["time","myfield","mytag"],"values":[["2016-05-19T18:37:57Z",90,"1"],["2016-05-19T18:37:58Z",90,"1"]]}]}]}
|
||||
application/x-msgpack:
|
||||
schema:
|
||||
type: string
|
||||
format: binary
|
||||
'429':
|
||||
description: Token is temporarily over quota. The Retry-After header describes when to try the read again.
|
||||
headers:
|
||||
Retry-After:
|
||||
description: A non-negative decimal integer indicating the seconds to delay after the response is received.
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
default:
|
||||
description: Error processing query
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
/write:
|
||||
post:
|
||||
operationId: PostLegacyWrite
|
||||
|
@ -13285,9 +13305,27 @@ paths:
|
|||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
description: Internal server error
|
||||
summary: Write time series data into InfluxDB in a V1-compatible format
|
||||
summary: Write data using a v1-compatible request
|
||||
description: |
|
||||
Writes data in line protocol syntax to the specified bucket using a v1-compatible request.
|
||||
|
||||
#### InfluxDB Cloud
|
||||
|
||||
- Validates and queues the request.
|
||||
- Handles the write asynchronously - the write might not have completed yet.
|
||||
- Returns a `Retry-After` header that describes when to try the write again.
|
||||
|
||||
#### InfluxDB OSS v2
|
||||
|
||||
- Validates the request and handles the write synchronously.
|
||||
- If all points were written successfully, responds with HTTP `2xx` status code
|
||||
- If any points were rejected, responds with HTTP `4xx` status code and details about the problem.
|
||||
|
||||
#### Related guides
|
||||
|
||||
- [Write data with the InfluxDB API](/influxdb/v2/write-data/developer-tools/api)
|
||||
tags:
|
||||
- Legacy Write
|
||||
- Write data (v1-compatible)
|
||||
components:
|
||||
examples:
|
||||
AuthorizationPostRequest:
|
||||
|
@ -13392,6 +13430,96 @@ components:
|
|||
required: false
|
||||
schema:
|
||||
type: string
|
||||
Accept:
|
||||
in: header
|
||||
name: Accept
|
||||
schema:
|
||||
default: application/json
|
||||
description: |
|
||||
Media type that the client can understand.
|
||||
|
||||
**Note**: With `application/csv`, query results include [**unix timestamps**](/influxdb/v2/reference/glossary/#unix-timestamp) instead of [RFC3339 timestamps](/influxdb/v2/reference/glossary/#rfc3339-timestamp).
|
||||
enum:
|
||||
- application/json
|
||||
- application/csv
|
||||
- text/csv
|
||||
- application/x-msgpack
|
||||
type: string
|
||||
AcceptEncoding:
|
||||
description: The content encoding (usually a compression algorithm) that the client can understand.
|
||||
in: header
|
||||
name: Accept-Encoding
|
||||
schema:
|
||||
default: identity
|
||||
description: The content coding. Use `gzip` for compressed data or `identity` for unmodified, uncompressed data.
|
||||
enum:
|
||||
- gzip
|
||||
- identity
|
||||
type: string
|
||||
Content-Type:
|
||||
in: header
|
||||
name: Content-Type
|
||||
schema:
|
||||
enum:
|
||||
- application/json
|
||||
type: string
|
||||
AuthV1Username:
|
||||
description: |
|
||||
The InfluxDB 1.x username to authenticate the request.
|
||||
If you provide an API token as the password, `u` is required, but can be any value.
|
||||
in: query
|
||||
name: u
|
||||
schema:
|
||||
type: string
|
||||
AuthV1Password:
|
||||
description: The InfluxDB 1.x password to authenticate the request.
|
||||
in: query
|
||||
name: p
|
||||
schema:
|
||||
type: string
|
||||
V1Database:
|
||||
description: |
|
||||
The database to query data from.
|
||||
This is mapped to an InfluxDB [bucket](/influxdb/v2/reference/glossary/#bucket).
|
||||
For more information, see [Database and retention policy mapping](/influxdb/v2/api/influxdb-1x/dbrp/).
|
||||
in: query
|
||||
name: db
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
V1RetentionPolicy:
|
||||
description: |
|
||||
The retention policy to query data from.
|
||||
This is mapped to an InfluxDB [bucket](/influxdb/v2/reference/glossary/#bucket).
|
||||
For more information, see [Database and retention policy mapping](/influxdb/v2/api/influxdb-1x/dbrp/).
|
||||
in: query
|
||||
name: rp
|
||||
schema:
|
||||
type: string
|
||||
V1Query:
|
||||
description: The InfluxQL query to execute. To execute multiple queries, delimit queries with a semicolon (`;`).
|
||||
in: query
|
||||
name: q
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
V1Epoch:
|
||||
description: |
|
||||
A unix timestamp precision.
|
||||
Formats timestamps as [unix (epoch) timestamps](/influxdb/v2/reference/glossary/#unix-timestamp) with the specified precision
|
||||
instead of [RFC3339 timestamps](/influxdb/v2/reference/glossary/#rfc3339-timestamp) with nanosecond precision.
|
||||
in: query
|
||||
name: epoch
|
||||
schema:
|
||||
enum:
|
||||
- ns
|
||||
- u
|
||||
- µ
|
||||
- ms
|
||||
- s
|
||||
- m
|
||||
- h
|
||||
type: string
|
||||
responses:
|
||||
AuthorizationError:
|
||||
content:
|
||||
|
@ -20038,13 +20166,16 @@ x-tagGroups:
|
|||
- Headers
|
||||
- Pagination
|
||||
- Response codes
|
||||
- Compatibility endpoints
|
||||
- name: All endpoints
|
||||
tags:
|
||||
- Authorizations (API tokens)
|
||||
- Authorizations (v1-compatible)
|
||||
- Backup
|
||||
- Buckets
|
||||
- Cells
|
||||
- Checks
|
||||
- Compatibility endpoints
|
||||
- Config
|
||||
- Dashboards
|
||||
- DBRPs
|
||||
|
@ -20052,15 +20183,13 @@ x-tagGroups:
|
|||
- Delete
|
||||
- Health
|
||||
- Labels
|
||||
- Legacy Authorizations
|
||||
- Legacy Query
|
||||
- Legacy Write
|
||||
- Metrics
|
||||
- NotificationEndpoints
|
||||
- NotificationRules
|
||||
- Organizations
|
||||
- Ping
|
||||
- Query
|
||||
- Query data (v1-compatible)
|
||||
- Ready
|
||||
- RemoteConnections
|
||||
- Replications
|
||||
|
@ -20082,3 +20211,4 @@ x-tagGroups:
|
|||
- Variables
|
||||
- Views
|
||||
- Write
|
||||
- Write data (v1-compatible)
|
||||
|
|
|
@ -34,8 +34,8 @@ and visit the `/docs` endpoint in a browser ([localhost:8086/docs](http://localh
|
|||
|
||||
## InfluxDB v1 compatibility API documentation
|
||||
|
||||
The InfluxDB v2 API includes [InfluxDB 1.x compatibility endpoints](/influxdb/v2/reference/api/influxdb-1x/)
|
||||
The InfluxDB v2 API includes [InfluxDB v1 compatibility endpoints and authentication](/influxdb/v2/api-guide/influxdb-1x/)
|
||||
that work with InfluxDB 1.x client libraries and third-party integrations like
|
||||
[Grafana](https://grafana.com) and others.
|
||||
|
||||
<a class="btn" href="/influxdb/v2/api/v1-compatibility/">View full v1 compatibility API documentation</a>
|
||||
<a class="btn" href="/influxdb/v2/api/v2/#tag/Compatibility-endpoints">View full v1 compatibility API documentation</a>
|
||||
|
|
|
@ -14,4 +14,5 @@ source: /shared/influxdb-v2/api-guide/api_intro.md
|
|||
---
|
||||
|
||||
<!-- The content for this file is located at
|
||||
// SOURCE content/shared/influxdb-v2/api-guide/api_intro.md -->
|
||||
// SOURCE content/shared/influxdb-v2/api-guide/api_intro.md
|
||||
-->
|
||||
|
|
|
@ -18,4 +18,5 @@ source: /shared/influxdb-v2/api-guide/influxdb-1x/_index.md
|
|||
---
|
||||
|
||||
<!-- The content for this file is located at
|
||||
// SOURCE content/shared/influxdb-v2/api-guide/influxdb-1x/_index.md -->
|
||||
// SOURCE content/shared/influxdb-v2/api-guide/influxdb-1x/_index.md
|
||||
-->
|
||||
|
|
|
@ -14,17 +14,15 @@ list_code_example: |
|
|||
<span class="api get">GET</span> http://localhost:8086/query
|
||||
</pre>
|
||||
related:
|
||||
- /influxdb/v2/query-data/execute-queries/influx-api/
|
||||
- /influxdb/v2/query-data/influxql
|
||||
aliases:
|
||||
- /influxdb/v2/reference/api/influxdb-1x/query/
|
||||
---
|
||||
|
||||
The `/query` 1.x compatibility endpoint queries InfluxDB {{< current-version >}} using **InfluxQL**.
|
||||
Use the `GET` request method to query data from the `/query` endpoint.
|
||||
Send an InfluxQL query in an HTTP `GET` or `POST` request to query data from the `/query` endpoint.
|
||||
|
||||
<pre>
|
||||
<span class="api get">GET</span> http://localhost:8086/query
|
||||
</pre>
|
||||
|
||||
The `/query` compatibility endpoint uses the **database** and **retention policy**
|
||||
specified in the query request to map the request to an InfluxDB bucket.
|
||||
|
@ -32,31 +30,32 @@ For more information, see [Database and retention policy mapping](/influxdb/v2/r
|
|||
|
||||
{{% show-in "cloud,cloud-serverless" %}}
|
||||
|
||||
{{% note %}}
|
||||
If you have an existing bucket that doesn't follow the **database/retention-policy** naming convention,
|
||||
you **must** [manually create a database and retention policy mapping](/influxdb/v2/query-data/influxql/dbrp/#create-dbrp-mappings)
|
||||
to query that bucket with the `/query` compatibility API.
|
||||
{{% /note %}}
|
||||
> [!Note]
|
||||
> If you have an existing bucket that doesn't follow the **database/retention-policy** naming convention,
|
||||
> you **must** [manually create a database and retention policy mapping](/influxdb/v2/query-data/influxql/dbrp/#create-dbrp-mappings)
|
||||
> to query that bucket with the `/query` compatibility API.
|
||||
|
||||
{{% /show-in %}}
|
||||
|
||||
## Authentication
|
||||
|
||||
Use one of the following authentication methods:
|
||||
* **token authentication**
|
||||
* **basic authentication with username and password**
|
||||
* **query string authentication with username and password**
|
||||
|
||||
_For more information, see [Authentication](/influxdb/v2/reference/api/influxdb-1x/#authentication)._
|
||||
- the 2.x `Authorization: Token` scheme in the header
|
||||
- the v1-compatible `u` and `p` query string parameters
|
||||
- the v1-compatible `Basic` authentication scheme in the header
|
||||
|
||||
For more information, see [Authentication for the 1.x compatibility API](/influxdb/v2/api-guide/influxdb-1x/).
|
||||
|
||||
## Query string parameters
|
||||
|
||||
### u
|
||||
(Optional) The 1.x **username** to authenticate the request.
|
||||
If you provide an API token as the password, `u` is required, but can be any value.
|
||||
_See [query string authentication](/influxdb/v2/reference/api/influxdb-1x/#query-string-authentication)._
|
||||
|
||||
### p
|
||||
(Optional) The 1.x **password** to authenticate the request.
|
||||
(Optional) The 1.x **password** or the 2.x API token to authenticate the request.
|
||||
_See [query string authentication](/influxdb/v2/reference/api/influxdb-1x/#query-string-authentication)._
|
||||
|
||||
### db
|
||||
|
@ -94,61 +93,65 @@ The following precisions are available:
|
|||
- [Return query results with millisecond Unix timestamps](#return-query-results-with-millisecond-unix-timestamps)
|
||||
- [Execute InfluxQL queries from a file](#execute-influxql-queries-from-a-file)
|
||||
|
||||
{{% code-placeholders "API_TOKEN" %}}
|
||||
{{% code-placeholders "INFLUX_USERNAME|INFLUX_PASSWORD_OR_TOKEN|API_TOKEN" %}}
|
||||
|
||||
##### Query using basic authentication
|
||||
|
||||
The following example:
|
||||
|
||||
- sends a `GET` request to the `/query` endpoint
|
||||
- uses the `Authorization` header with the `Basic` scheme (compatible with InfluxDB 1.x) to provide username and password credentials
|
||||
- uses the default retention policy for the database
|
||||
|
||||
{{% show-in "v2" %}}
|
||||
|
||||
{{< code-tabs-wrapper >}}
|
||||
{{% code-tabs %}}
|
||||
[curl](#curl)
|
||||
[Node.js](#nodejs)
|
||||
{{% /code-tabs %}}
|
||||
{{% code-tab-content %}}
|
||||
|
||||
<!--pytest.mark.skip-->
|
||||
|
||||
```sh
|
||||
{{% get-shared-text "api/v1-compat/auth/oss/basic-auth.sh" %}}
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
{{% code-tab-content %}}
|
||||
```js
|
||||
{{% get-shared-text "api/v1-compat/auth/oss/basic-auth.js" %}}
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
{{< /code-tabs-wrapper >}}
|
||||
##############################################################################
|
||||
# Use Basic authentication with an
|
||||
# InfluxDB v1-compatible username and password
|
||||
# to query the InfluxDB 1.x compatibility API.
|
||||
#
|
||||
# INFLUX_USERNAME: your v1-compatible username.
|
||||
# INFLUX_PASSWORD_OR_TOKEN: your API token or v1-compatible password.
|
||||
##############################################################################
|
||||
|
||||
curl --get "http://{{< influxdb/host >}}/query" \
|
||||
--user "INFLUX_USERNAME":"INFLUX_PASSWORD_OR_TOKEN" \
|
||||
--data-urlencode "db=BUCKET_NAME" \
|
||||
--data-urlencode "q=SELECT * FROM cpu_usage"
|
||||
```
|
||||
{{% /show-in %}}
|
||||
|
||||
{{% show-in "cloud,cloud-serverless" %}}
|
||||
|
||||
{{< code-tabs-wrapper >}}
|
||||
{{% code-tabs %}}
|
||||
[curl](#curl)
|
||||
[Node.js](#nodejs)
|
||||
{{% /code-tabs %}}
|
||||
{{% code-tab-content %}}
|
||||
|
||||
<!--pytest.mark.skip-->
|
||||
|
||||
```sh
|
||||
{{% get-shared-text "api/v1-compat/auth/cloud/basic-auth.sh" %}}
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
{{% code-tab-content %}}
|
||||
```js
|
||||
{{% get-shared-text "api/v1-compat/auth/cloud/basic-auth.js" %}}
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
{{< /code-tabs-wrapper >}}
|
||||
|
||||
|
||||
{{% /show-in %}}
|
||||
|
||||
##### Query using an HTTP POST request
|
||||
|
||||
```bash
|
||||
curl \
|
||||
--request POST \
|
||||
"http://{{< influxdb/host >}}/query?db=DATABASE_NAME&rp=RETENTION_POLICY" \
|
||||
--user "INFLUX_USERNAME":"INFLUX_PASSWORD_OR_TOKEN" \
|
||||
--header "Content-type: application/vnd.influxql" \
|
||||
--data "SELECT * FROM cpu_usage WHERE time > now() - 1h"
|
||||
```
|
||||
|
||||
##### Query a non-default retention policy
|
||||
|
||||
The following example:
|
||||
|
||||
- sends a `GET` request to the `/query` endpoint
|
||||
- uses the `Authorization` header with the `Token` scheme (compatible with InfluxDB 2.x) to provide the API token
|
||||
- queries a custom retention policy mapped for the database
|
||||
|
||||
<!--test:setup
|
||||
```sh
|
||||
service influxdb start && \
|
||||
|
@ -162,43 +165,56 @@ influx setup \
|
|||
-->
|
||||
|
||||
```sh
|
||||
curl --get http://localhost:8086/query \
|
||||
curl --get http://{{< influxdb/host >}}/query \
|
||||
--header "Authorization: Token API_TOKEN" \
|
||||
--data-urlencode "db=mydb" \
|
||||
--data-urlencode "rp=customrp" \
|
||||
--data-urlencode "db=DATABASE_NAME" \
|
||||
--data-urlencode "rp=RETENTION_POLICY_NAME" \
|
||||
--data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1"
|
||||
```
|
||||
|
||||
##### Execute multiple queries
|
||||
|
||||
```sh
|
||||
curl --get http://localhost:8086/query \
|
||||
curl --get http://{{< influxdb/host >}}/query \
|
||||
--header "Authorization: Token API_TOKEN" \
|
||||
--data-urlencode "db=mydb" \
|
||||
--data-urlencode "db=DATABASE_NAME" \
|
||||
--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
|
||||
```sh
|
||||
curl --get http://localhost:8086/query \
|
||||
curl --get http://{{< influxdb/host >}}/query \
|
||||
--header "Authorization: Token API_TOKEN" \
|
||||
--data-urlencode "db=mydb" \
|
||||
--data-urlencode "rp=myrp" \
|
||||
--data-urlencode "db=DATABASE_NAME" \
|
||||
--data-urlencode "rp=RETENTION_POLICY_NAME" \
|
||||
--data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1" \
|
||||
--data-urlencode "epoch=ms"
|
||||
```
|
||||
|
||||
##### Execute InfluxQL queries from a file
|
||||
```sh
|
||||
curl --get http://localhost:8086/query \
|
||||
curl --get http://{{< influxdb/host >}}/query \
|
||||
--header "Authorization: Token API_TOKEN" \
|
||||
--data-urlencode "db=mydb" \
|
||||
--data-urlencode "q@path/to/influxql.txt" \
|
||||
--data-urlencode "async=true"
|
||||
--data-urlencode "db=DATABASE_NAME" \
|
||||
--data-urlencode "q@path/to/influxql.txt"
|
||||
```
|
||||
|
||||
##### Return a gzip-compressed response
|
||||
```sh
|
||||
curl --get http://{{< influxdb/host >}}/query \
|
||||
--header 'Accept-Encoding: gzip' \
|
||||
--header "Authorization: Token API_TOKEN" \
|
||||
--data-urlencode "db=DATABASE_NAME" \
|
||||
--data-urlencode "q=SELECT used_percent FROM mem WHERE host=host1"
|
||||
```
|
||||
{{% /code-placeholders %}}
|
||||
|
||||
Replace the following:
|
||||
|
||||
- {{% code-placeholder-key %}}`API_TOKEN`{{% /code-placeholder-key %}}: your InfluxDB [API token](/influxdb/v2/admin/tokens/)
|
||||
- {{% code-placeholder-key %}}`DATABASE_NAME`{{% /code-placeholder-key %}}: the name of the database to query.
|
||||
In InfluxDB 2.x, databases and retention policies map to [buckets](/influxdb/v2/admin/buckets/).
|
||||
- {{% code-placeholder-key %}}`RETENTION_POLICY_NAME`{{% /code-placeholder-key %}}: the name of the retention policy to query.
|
||||
In InfluxDB 2.x, databases and retention policies map to [buckets](/influxdb/v2/admin/buckets/).
|
||||
|
||||
_For more information about the database and retention policy mapping, see [Database and retention policy mapping](/influxdb/v2/reference/api/influxdb-1x/dbrp)._
|
|
@ -12,4 +12,5 @@ source: /shared/influxdb-v2/api-guide/tutorials/_index.md
|
|||
---
|
||||
|
||||
<!-- The content for this file is located at
|
||||
// SOURCE content/shared/influxdb-v2/api-guide/tutorials/_index.md -->
|
||||
// SOURCE content/shared/influxdb-v2/api-guide/tutorials/_index.md
|
||||
-->
|
||||
|
|
|
@ -328,6 +328,6 @@ which requires authentication.
|
|||
|
||||
**For these external clients to work with InfluxDB {{< current-version >}}:**
|
||||
|
||||
1. [Manually create a 1.x-compatible authorization](/influxdb/v2/upgrade/v1-to-v2/manual-upgrade/#create-a-1x-compatible-authorization).
|
||||
1. [Manually create a v1-compatible authorization](/influxdb/v2/upgrade/v1-to-v2/manual-upgrade/#create-a-1x-compatible-authorization).
|
||||
2. Update the client configuration to use the username and password associated
|
||||
with your 1.x-compatible authorization.
|
||||
with your v1-compatible authorization.
|
||||
|
|
|
@ -3,7 +3,7 @@ title: Manually upgrade from InfluxDB 1.x to 2.7
|
|||
list_title: Manually upgrade from 1.x to 2.7
|
||||
description: >
|
||||
To manually upgrade from InfluxDB 1.x to InfluxDB 2.7, migrate data, create
|
||||
1.x-compatible authorizations, and create database and retention policy
|
||||
v1-compatible authorizations, and create database and retention policy
|
||||
(DBRP) mappings.
|
||||
menu:
|
||||
influxdb_v2:
|
||||
|
|
|
@ -11,4 +11,5 @@ source: /shared/influxdb-v2/query-data/execute-queries/influx-api.md
|
|||
---
|
||||
|
||||
<!-- The content for this file is located at
|
||||
// SOURCE content/shared/influxdb-v2/query-data/execute-queries/influx-api.md -->
|
||||
// SOURCE content/shared/influxdb-v2/query-data/execute-queries/influx-api.md
|
||||
-->
|
||||
|
|
|
@ -26,7 +26,7 @@ The URL in the examples depends on the version and location of your InfluxDB {{<
|
|||
|
||||
{{< code-tabs-wrapper >}}
|
||||
{{% code-tabs %}}
|
||||
[Curl](#curl)
|
||||
[cURL](#curl)
|
||||
[Node.js](#nodejs)
|
||||
{{% /code-tabs %}}
|
||||
{{% code-tab-content %}}
|
||||
|
|
|
@ -10,7 +10,8 @@ menu:
|
|||
parent: Write data
|
||||
influxdb/v2/tags: [write, line protocol, errors]
|
||||
related:
|
||||
- /influxdb/v2/api/#tag/Write, InfluxDB API /write endpoint
|
||||
- /influxdb/v2/api/v2/#operation/PostLegacyWrite, InfluxDB API /write endpoint
|
||||
- /influxdb/v2/api/v2/#operation/PostWrite, InfluxDB API /api/v2/write endpoint
|
||||
- /influxdb/v2/reference/internals
|
||||
- /influxdb/v2/reference/cli/influx/write
|
||||
---
|
||||
|
|
|
@ -5,13 +5,12 @@ This section guides you through the most commonly used API methods.
|
|||
|
||||
For detailed documentation on the entire API, see the [InfluxDB v2 API Reference](/influxdb/version/reference/api/#influxdb-v2-api-documentation).
|
||||
|
||||
{{% note %}}
|
||||
If you need to use InfluxDB {{< current-version >}} with **InfluxDB 1.x** API clients and integrations, see the [1.x compatibility API](/influxdb/version/reference/api/#influxdb-v1-compatibility-api-reference-documentation).
|
||||
{{% /note %}}
|
||||
> [!Note]
|
||||
> If you need to use InfluxDB {{< current-version >}} with **InfluxDB 1.x** API clients and integrations, see the [1.x compatibility API guide](/influxdb/version/api-guide/influxdb-1x).
|
||||
|
||||
## Bootstrap your application
|
||||
|
||||
With most API requests, you'll need to provide a minimum of your InfluxDB URL and Authorization Token (API Token).
|
||||
With most API requests, you'll need to provide a minimum of your InfluxDB URL and [Authorization Token (API Token)](/influxdb/version/admin/tokens/).
|
||||
|
||||
[Install InfluxDB OSS v2.x](/influxdb/version/install/) or upgrade to
|
||||
an [InfluxDB Cloud account](/influxdb/cloud/sign-up).
|
||||
|
@ -19,11 +18,14 @@ an [InfluxDB Cloud account](/influxdb/cloud/sign-up).
|
|||
### Authentication
|
||||
|
||||
InfluxDB uses [API tokens](/influxdb/version/admin/tokens/) to authorize API requests.
|
||||
InfluxDB filters API requests and response data based on the permissions associated with the token.
|
||||
|
||||
1. Before exploring the API, use the InfluxDB UI to
|
||||
1. Before exploring the API, use the `influx` CLI or the InfluxDB UI to
|
||||
[create an initial API token](/influxdb/version/admin/tokens/create-token/) for your application.
|
||||
|
||||
2. Include your API token in an `Authorization: Token YOUR_API_TOKEN` HTTP header with each request.
|
||||
1. Include your API token in an `Authorization: Token API_TOKEN` HTTP header with each request--for example:
|
||||
|
||||
{{% code-placeholders "API_TOKEN" %}}
|
||||
|
||||
{{< code-tabs-wrapper >}}
|
||||
{{% code-tabs %}}
|
||||
|
@ -31,28 +33,94 @@ InfluxDB uses [API tokens](/influxdb/version/admin/tokens/) to authorize API req
|
|||
[Node.js](#nodejs)
|
||||
{{% /code-tabs %}}
|
||||
{{% code-tab-content %}}
|
||||
```sh
|
||||
{{% get-shared-text "api/v2.0/auth/oss/token-auth.sh" %}}
|
||||
```bash
|
||||
# Use a token to authorize a GET request to the InfluxDB API.
|
||||
# List buckets in your organization that the token can read.
|
||||
curl -X GET "http://{{< influxdb/host >}}/api/v2/buckets" \
|
||||
--header 'Accept: application/json' \
|
||||
--header 'Authorization: Token API_TOKEN'
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
{{% code-tab-content %}}
|
||||
```js
|
||||
{{% get-shared-text "api/v2.0/auth/oss/token-auth.js" %}}
|
||||
/**
|
||||
* Use a token to authorize a GET request to the InfluxDB API.
|
||||
* List buckets in your organization that the token can read.
|
||||
*/
|
||||
|
||||
const https = require('https');
|
||||
|
||||
function listBuckets() {
|
||||
|
||||
const options = {
|
||||
host: '{{< influxdb/host >}}',
|
||||
path: "/api/v2/buckets",
|
||||
headers: {
|
||||
'Authorization': 'Token API_TOKEN',
|
||||
'Content-type': 'application/json'
|
||||
},
|
||||
};
|
||||
|
||||
const request = https.get(options, (response) => {
|
||||
let rawData = '';
|
||||
response.on('data', () => {
|
||||
response.on('data', (chunk) => { rawData += chunk; });
|
||||
})
|
||||
response.on('end', () => {
|
||||
console.log(rawData);
|
||||
})
|
||||
});
|
||||
|
||||
request.end();
|
||||
}
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
{{< /code-tabs-wrapper >}}
|
||||
|
||||
Postman is another popular tool for exploring APIs. See how to [send authenticated requests with Postman](/influxdb/version/tools/postman/#send-authenticated-api-requests-with-postman).
|
||||
{{% /code-placeholders %}}
|
||||
|
||||
> [!Note]
|
||||
> Postman is another popular tool for exploring APIs.
|
||||
> See how to [send authenticated requests with Postman](/influxdb/version/tools/postman/#send-authenticated-api-requests-with-postman).
|
||||
|
||||
## Buckets API
|
||||
|
||||
Before writing data you'll need to create a Bucket in InfluxDB.
|
||||
[Create a bucket](/influxdb/version/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api) using an HTTP request to the InfluxDB API `/buckets` endpoint.
|
||||
Before writing data you'll need to create a bucket in your InfluxDB instance.
|
||||
To use the API to create a bucket, send a request to the following endpoint:
|
||||
|
||||
```sh
|
||||
{{% get-shared-text "api/v2.0/buckets/oss/create.sh" %}}
|
||||
{{% api-endpoint method="POST" endpoint="/api/v2/buckets" api-ref="/influxdb/version/api/v2/#operation/PostBuckets" %}}
|
||||
|
||||
{{% code-placeholders "API_TOKEN|ORG_ID|BUCKET_NAME|RETENTION_PERIOD_SECONDS" %}}
|
||||
|
||||
```bash
|
||||
curl --request POST \
|
||||
"http://localhost:8086/api/v2/buckets" \
|
||||
--header "Authorization: Token API_TOKEN" \
|
||||
--json '{
|
||||
"orgID": "'"ORG_ID"'",
|
||||
"name": "BUCKET_NAME",
|
||||
"retentionRules": [
|
||||
{
|
||||
"type": "expire",
|
||||
"everySeconds": RETENTION_PERIOD_SECONDS,
|
||||
"shardGroupDurationSeconds": 0
|
||||
}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
{{% /code-placeholders %}}
|
||||
|
||||
Replace the following placeholders with your values:
|
||||
|
||||
- {{% code-placeholder-key %}}`API_TOKEN`{{% /code-placeholder-key %}} - your [token](/influxdb/version/admin/tokens/).
|
||||
- {{% code-placeholder-key %}}`ORG_ID`{{% /code-placeholder-key %}} - the ID of the [organization](/influxdb/version/admin/organizations/) that owns the bucket.
|
||||
- {{% code-placeholder-key %}}`BUCKET_NAME`{{% /code-placeholder-key %}} - the name of the [bucket](/influxdb/version/admin/buckets/) to create.
|
||||
- Optional: {{% code-placeholder-key %}}`RETENTION_PERIOD_SECONDS`{{% /code-placeholder-key %}} - the [retention period](/influxdb/version/reference/glossary/#retention-period) (in number of seconds) to retain data in the bucket. Default is `0` (infinite retention).
|
||||
- For example, `31536000` (1 year) or `604800` (7 days).
|
||||
|
||||
For more information, see [Create a bucket](/influxdb/version/admin/buckets/create-bucket/#create-a-bucket-using-the-influxdb-api).
|
||||
|
||||
## Write API
|
||||
|
||||
[Write data to InfluxDB](/influxdb/version/write-data/developer-tools/api/) using an HTTP request to the InfluxDB API `/api/v2/write` endpoint.
|
||||
|
|
|
@ -7,7 +7,7 @@ InfluxDB 1.x client libraries and third-party integrations like [Grafana](https:
|
|||
## Authentication
|
||||
|
||||
InfluxDB 1.x compatibility endpoints require all query and write requests to be authenticated with an
|
||||
[API token](/influxdb/version/admin/tokens/) or 1.x-compatible
|
||||
[API token](/influxdb/version/admin/tokens/) or v1-compatible
|
||||
credentials.
|
||||
|
||||
* [Authenticate with the Token scheme](#authenticate-with-the-token-scheme)
|
||||
|
@ -67,12 +67,12 @@ Username and password schemes require the following credentials:
|
|||
{{% note %}}
|
||||
#### Password or Token
|
||||
|
||||
If you have [set a password](/influxdb/version/install/upgrade/v1-to-v2/manual-upgrade/#1x-compatible-authorizations) for the 1.x-compatible username, provide the 1.x-compatible password.
|
||||
If you haven't set a password for the 1.x-compatible username, provide the InfluxDB [authentication token](/influxdb/version/admin/tokens/) as the password.
|
||||
If you have [set a password](/influxdb/version/install/upgrade/v1-to-v2/manual-upgrade/#1x-compatible-authorizations) for the v1-compatible username, provide the v1-compatible password.
|
||||
If you haven't set a password for the v1-compatible username, provide the InfluxDB [authentication token](/influxdb/version/admin/tokens/) as the password.
|
||||
{{% /note %}}
|
||||
|
||||
For more information, see how to create and manage
|
||||
[1.x-compatible authorizations](/influxdb/version/install/upgrade/v1-to-v2/manual-upgrade/#1x-compatible-authorizations)
|
||||
[v1-compatible authorizations](/influxdb/version/install/upgrade/v1-to-v2/manual-upgrade/#1x-compatible-authorizations)
|
||||
when manually upgrading from InfluxDB v1 to v2.
|
||||
|
||||
{{% /show-in %}}
|
||||
|
|
|
@ -496,7 +496,7 @@ To query data from InfluxDB using InfluxQL and the InfluxDB HTTP API, send a req
|
|||
to the InfluxDB API [`/query` 1.X compatibility endpoint](/influxdb/version/reference/api/influxdb-1x/query/)
|
||||
using the `POST` request method.
|
||||
|
||||
{{< api-endpoint endpoint="http://localhost:8086/query" method="post" api-ref="/influxdb/version/api/v1-compatibility/#operation/PostQueryV1" >}}
|
||||
{{< api-endpoint endpoint="http://localhost:8086/query" method="post" api-ref="/influxdb/version/api/v1/#operation/PostQueryV1" >}}
|
||||
|
||||
Include the following with your request:
|
||||
|
||||
|
|
|
@ -2,34 +2,42 @@
|
|||
The [InfluxDB v2 API](/influxdb/version/reference/api) provides a programmatic interface for all interactions with InfluxDB.
|
||||
To query InfluxDB {{< current-version >}}, do one of the following:
|
||||
|
||||
- Send a Flux query request to the [`/api/v2/query`](/influxdb/version/api/#operation/PostQueryAnalyze) endpoint.
|
||||
- Send an InfluxQL query request to the [/query 1.x compatibility API](/influxdb/version/reference/api/influxdb-1x/query/).
|
||||
- [Send a Flux query request](#send-a-flux-query-request)
|
||||
- [Send an InfluxQL query request](#send-an-influxql-query-request)
|
||||
|
||||
## Send a Flux query request
|
||||
|
||||
Send a Flux query request to the following endpoint:
|
||||
|
||||
{{% api-endpoint method="POST" endpoint="/api/v2/query" api-ref="/influxdb/version/api/#operation/PostQueryAnalyze" %}}
|
||||
|
||||
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.
|
||||
- Your organization via the `org` or `orgID` URL parameters
|
||||
- Headers:
|
||||
- `Authorization: Token <API_TOKEN>`
|
||||
- `Accept: application/csv`
|
||||
- `Content-type: application/vnd.flux`
|
||||
- Your Flux query text in the request body
|
||||
|
||||
{{% note %}}
|
||||
#### 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.
|
||||
{{% /note %}}
|
||||
> [!Note]
|
||||
> #### Use gzip to compress a large 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 {{< current-version >}}:
|
||||
The following example shows how to use cURL to send a Flux query to InfluxDB {{< current-version >}}:
|
||||
|
||||
{{% code-placeholders "ORG_ID|API_TOKEN|BUCKET_NAME" %}}
|
||||
```bash
|
||||
{{< code-tabs-wrapper >}}
|
||||
{{% code-tabs %}}
|
||||
[Without compression](#)
|
||||
|
@ -39,11 +47,11 @@ Below is an example `curl` request that sends a Flux query to InfluxDB {{< curre
|
|||
{{% code-tab-content %}}
|
||||
```bash
|
||||
curl --request POST \
|
||||
http://localhost:8086/api/v2/query?orgID=INFLUX_ORG_ID \
|
||||
--header 'Authorization: Token INFLUX_TOKEN' \
|
||||
http://localhost:8086/api/v2/query?orgID=ORG_ID \
|
||||
--header 'Authorization: Token API_TOKEN' \
|
||||
--header 'Accept: application/csv' \
|
||||
--header 'Content-type: application/vnd.flux' \
|
||||
--data 'from(bucket:"example-bucket")
|
||||
--data 'from(bucket:"BUCKET_NAME")
|
||||
|> range(start: -12h)
|
||||
|> filter(fn: (r) => r._measurement == "example-measurement")
|
||||
|> aggregateWindow(every: 1h, fn: mean)'
|
||||
|
@ -53,12 +61,12 @@ curl --request POST \
|
|||
{{% code-tab-content %}}
|
||||
```bash
|
||||
curl --request POST \
|
||||
http://localhost:8086/api/v2/query?orgID=INFLUX_ORG_ID \
|
||||
--header 'Authorization: Token INFLUX_TOKEN' \
|
||||
http://localhost:8086/api/v2/query?orgID=ORG_ID \
|
||||
--header 'Authorization: Token API_TOKEN' \
|
||||
--header 'Accept: application/csv' \
|
||||
--header 'Content-type: application/vnd.flux' \
|
||||
--header 'Accept-Encoding: gzip' \
|
||||
--data 'from(bucket:"example-bucket")
|
||||
--data 'from(bucket:"BUCKET_NAME")
|
||||
|> range(start: -12h)
|
||||
|> filter(fn: (r) => r._measurement == "example-measurement")
|
||||
|> aggregateWindow(every: 1h, fn: mean)'
|
||||
|
@ -66,9 +74,76 @@ curl --request POST \
|
|||
{{% /code-tab-content %}}
|
||||
{{< /code-tabs-wrapper >}}
|
||||
|
||||
{{% /code-placeholders %}}
|
||||
|
||||
Replace the following with your values:
|
||||
|
||||
- {{% code-placeholder-key %}}`ORG_ID`{{% /code-placeholder-key %}} - the ID of the [organization](/influxdb/version/admin/organizations/) that owns the bucket.
|
||||
- {{% code-placeholder-key %}}`API_TOKEN`{{% /code-placeholder-key %}} - your [token](/influxdb/version/admin/tokens/).
|
||||
- {{% code-placeholder-key %}}`BUCKET_NAME`{{% /code-placeholder-key %}} - the name of the [bucket](/influxdb/version/admin/buckets/) to create.
|
||||
|
||||
## Send an InfluxQL query request
|
||||
|
||||
You can query InfluxDB {{< current-version >}} using the InfluxQL query language with the v1-compatible API.
|
||||
Send an InfluxQL query in an HTTP `GET` or `POST` request to the following endpoint:
|
||||
|
||||
{{% api-endpoint endpoint="/query" api-ref="/influxdb/v2/api/v2/#operation/GetLegacyQuery" %}}
|
||||
|
||||
In your request, set the following:
|
||||
|
||||
- [1.x-compatible or 2.x authentication](/influxdb/v2/api-guide/influxdb-1x/#authentication) credentials
|
||||
- Headers:
|
||||
- `Accept: application/csv` or `Accept: application/json`
|
||||
- `Content-type: application/vnd.influxql`
|
||||
- Your InfluxQL query text in the request body or the `q` URL parameter
|
||||
|
||||
> [!Note]
|
||||
> If you have an existing bucket that doesn't follow the **database/retention-policy** naming convention,
|
||||
> you **must** [manually create a database and retention policy mapping](/influxdb/v2/query-data/influxql/dbrp/#create-dbrp-mappings)
|
||||
> to query that bucket with the `/query` compatibility API.
|
||||
|
||||
#### InfluxQL - Example query request
|
||||
|
||||
Below is an example `curl` request that sends an InfluxQL query to InfluxDB {{< current-version >}}:
|
||||
The following example shows how to use cURL to send an InfluxQL query to InfluxDB {{< current-version >}} using 1.x compatible authentication:
|
||||
|
||||
{{% code-placeholders "API_TOKEN|BUCKET_NAME|RETENTION_POLICY_NAME" %}}
|
||||
|
||||
{{< code-tabs-wrapper >}}
|
||||
{{% code-tabs %}}
|
||||
[HTTP POST](#)
|
||||
[HTTP GET](#)
|
||||
{{% /code-tabs %}}
|
||||
|
||||
{{% code-tab-content %}}
|
||||
```bash
|
||||
# 1.x compatible POST request using Basic authentication and InfluxQL
|
||||
curl --request POST \
|
||||
"http://localhost:8086/query?db=BUCKET_NAME&rp=RETENTION_POLICY&p=API_TOKEN&u=ignored" \
|
||||
--header "Content-type: application/vnd.influxql" \
|
||||
--data "SELECT * FROM home WHERE time < now()"
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
{{% code-tab-content %}}
|
||||
```bash
|
||||
# 1.x compatible GET request using Basic authentication and InfluxQL
|
||||
curl --get "http://localhost:8086/query" \
|
||||
--header "Accept: application/json" \
|
||||
--data-urlencode "q=SELECT * FROM home WHERE time < now()" \
|
||||
--data-urlencode "db=BUCKET_NAME" \
|
||||
--data-urlencode "rp=RETENTION_POLICY" \
|
||||
--data-urlencode "u=ignored" \
|
||||
--data-urlencode "p=API_TOKEN"
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
{{< /code-tabs-wrapper >}}
|
||||
|
||||
{{% /code-placeholders %}}
|
||||
Replace the following with your values:
|
||||
- {{% code-placeholder-key %}}`API_TOKEN`{{% /code-placeholder-key %}} - your [token](/influxdb/version/admin/tokens/).
|
||||
- {{% code-placeholder-key %}}`BUCKET_NAME`{{% /code-placeholder-key %}} - the name of the [bucket](/influxdb/version/admin/buckets/) to create.
|
||||
- {{% code-placeholder-key %}}`RETENTION_POLICY_NAME`{{% /code-placeholder-key %}} - the name of the 1.x retention policy to use for the query.
|
||||
|
||||
{{% code-placeholders "ORG_ID|API_TOKEN|BUCKET_NAME|RETENTION_POLICY_NAME" %}}
|
||||
|
||||
{{< code-tabs-wrapper >}}
|
||||
{{% code-tabs %}}
|
||||
|
@ -78,24 +153,40 @@ Below is an example `curl` request that sends an InfluxQL query to InfluxDB {{<
|
|||
|
||||
{{% code-tab-content %}}
|
||||
```bash
|
||||
curl --request -G http://localhost:8086/query?orgID=INFLUX_ORG_ID&database=MyDB&retention_policy=MyRP \
|
||||
--header 'Authorization: Token INFLUX_TOKEN' \
|
||||
curl --get "http://localhost:8086/query" \
|
||||
--header 'Accept: application/csv' \
|
||||
--header 'Content-type: application/json' \
|
||||
--data-urlencode "db=BUCKET_NAME" \
|
||||
--data-urlencode "rp=RETENTION_POLICY_NAME" \
|
||||
--data-urlencode "p=API_TOKEN" \
|
||||
--data-urlencode "u=ignored" \
|
||||
--data-urlencode "q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1"
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
|
||||
{{% code-tab-content %}}
|
||||
|
||||
```bash
|
||||
curl --request -G http://localhost:8086/query?orgID=INFLUX_ORG_ID&database=MyDB&retention_policy=MyRP \
|
||||
--header 'Authorization: Token INFLUX_TOKEN' \
|
||||
curl --get "http://localhost:8086/query" \
|
||||
--header 'Accept: application/csv' \
|
||||
--header 'Content-type: application/json' \
|
||||
--header 'Accept-Encoding: gzip' \
|
||||
--data-urlencode "db=BUCKET_NAME" \
|
||||
--data-urlencode "rp=RETENTION_POLICY_NAME" \
|
||||
--data-urlencode "p=API_TOKEN" \
|
||||
--data-urlencode "u=ignored" \
|
||||
--data-urlencode "q=SELECT used_percent FROM example-db.example-rp.example-measurement WHERE host=host1"
|
||||
```
|
||||
```
|
||||
{{% /code-tab-content %}}
|
||||
{{< /code-tabs-wrapper >}}
|
||||
|
||||
{{% /code-placeholders %}}
|
||||
|
||||
Replace the following with your values:
|
||||
|
||||
- {{% code-placeholder-key %}}`ORG_ID`{{% /code-placeholder-key %}} - the ID of the [organization](/influxdb/version/admin/organizations/) that owns the bucket.
|
||||
- {{% code-placeholder-key %}}`API_TOKEN`{{% /code-placeholder-key %}} - your [token](/influxdb/version/admin/tokens/).
|
||||
- {{% code-placeholder-key %}}`BUCKET_NAME`{{% /code-placeholder-key %}} - the name of the [bucket](/influxdb/version/admin/buckets/) to create.
|
||||
- {{% code-placeholder-key %}}`RETENTION_POLICY_NAME`{{% /code-placeholder-key %}} - the name of the 1.x retention policy to use for the query.
|
||||
|
||||
InfluxDB returns the query results in [annotated CSV](/influxdb/version/reference/syntax/annotated-csv/).
|
||||
|
|
|
@ -191,7 +191,7 @@ InfluxQL requires single quotes around tag values in the `WHERE` clause.
|
|||
|
||||
{{% /expand %}}
|
||||
|
||||
{{% expand "Select data with specific field key-values and tag key-valuest" %}}
|
||||
{{% expand "Select data with specific field key-values and tag key-values" %}}
|
||||
|
||||
```sql
|
||||
SELECT "water_level" FROM "h2o_feet" WHERE "location" <> 'santa_monica' AND (water_level < -0.59 OR water_level > 9.95)
|
||||
|
|
|
@ -6,7 +6,7 @@ InfluxDB {{< current-version >}} uses [API tokens](/influxdb/version/admin/token
|
|||
The [1.x compatibility API](/influxdb/version/reference/api/influxdb-1x/) lets clients authenticate with InfluxDB {{< current-version >}} using the InfluxDB 1.x convention of username and password.
|
||||
|
||||
{{% note %}}
|
||||
1.x-compatible authorizations are separate from the credentials used to log
|
||||
v1-compatible authorizations are separate from the credentials used to log
|
||||
into the InfluxDB user interface.
|
||||
{{% /note %}}
|
||||
|
||||
|
|
|
@ -664,8 +664,8 @@ from(bucket: "example-bucket")
|
|||
{{% /show-in %}}
|
||||
|
||||
Using InfluxQL with InfluxDB {{< current-version >}} is made possible by the
|
||||
[1.x compatibility API](/influxdb/version/reference/api/influxdb-1x/) which replicates
|
||||
the `/query` endpoint from InfluxDB 1.x. This allows all InfluxDB 1.x-compatible
|
||||
[v1 compatibility API](/influxdb/version/reference/api/influxdb-1x/) which replicates
|
||||
the `/query` endpoint from InfluxDB 1.x. This allows all InfluxDB v1-compatible
|
||||
clients to work with InfluxDB {{< current-version >}}. However, InfluxQL relies
|
||||
on a database and retention policy data model doesn't exist in InfluxDB
|
||||
{{< current-version >}}, but has been replaced by [buckets](/influxdb/version/reference/glossary/#bucket).
|
||||
|
|
Loading…
Reference in New Issue