Skip to content

Fix OSS v2 /query compatibility API specs and examples #6088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions api-docs/influxdb/v2/.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
1 change: 1 addition & 0 deletions api-docs/influxdb/v2/v2/content/tag-groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
- Headers
- Pagination
- Response codes
- Compatibility endpoints
- name: All endpoints
tags: []
340 changes: 233 additions & 107 deletions api-docs/influxdb/v2/v2/ref.yml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions content/influxdb/v2/api-guide/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
3 changes: 2 additions & 1 deletion content/influxdb/v2/api-guide/api_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-->
3 changes: 2 additions & 1 deletion content/influxdb/v2/api-guide/influxdb-1x/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-->
132 changes: 74 additions & 58 deletions content/influxdb/v2/api-guide/influxdb-1x/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,48 @@ 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.
For more information, see [Database and retention policy mapping](/influxdb/v2/reference/api/influxdb-1x/dbrp).

{{% 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
Expand Down Expand Up @@ -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

{{% show-in "v2" %}}
The following example:

{{< code-tabs-wrapper >}}
{{% code-tabs %}}
[curl](#curl)
[Node.js](#nodejs)
{{% /code-tabs %}}
{{% code-tab-content %}}
- 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" %}}
<!--pytest.mark.skip-->

```sh
{{% get-shared-text "api/v1-compat/auth/oss/basic-auth.sh" %}}
##############################################################################
# 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"
```
{{% /code-tab-content %}}
{{% code-tab-content %}}
```js
{{% get-shared-text "api/v1-compat/auth/oss/basic-auth.js" %}}
```
{{% /code-tab-content %}}
{{< /code-tabs-wrapper >}}

{{% /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 && \
Expand All @@ -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)._
3 changes: 2 additions & 1 deletion content/influxdb/v2/api-guide/tutorials/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-->
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion content/influxdb/v2/query-data/execute-queries/influx-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-->
4 changes: 2 additions & 2 deletions content/influxdb/v2/query-data/influxql/_index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Query data with InfluxQL
description: >
Use the [InfluxDB 1.x `/query` compatibility endpoint](/influxdb/v2/reference/api/influxdb-1x/query)
to query data in InfluxDB Cloud and InfluxDB OSS 2.4 with **InfluxQL**.
Use the InfluxDB v1 `/query` compatibility endpoint
to query data in InfluxDB v2 using InfluxQL.
weight: 102
influxdb/v2/tags: [influxql, query]
menu:
Expand Down
2 changes: 1 addition & 1 deletion content/influxdb/v2/write-data/developer-tools/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}}
Expand Down
3 changes: 2 additions & 1 deletion content/influxdb/v2/write-data/troubleshoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
source: /shared/influxdb-v2/write-data/troubleshoot.md
Expand Down
Loading