chore(influxdb3): Add auth header to API request samples
parent
14a6f40830
commit
6041afb396
|
@ -93,7 +93,7 @@ that surround field names._
|
|||
|
||||
```bash
|
||||
curl "http://localhost:8181/api/v3/query_sql" \
|
||||
--header "Content-Type: application/json" \
|
||||
--header "Authorization: Bearer AUTH_TOKEN" \
|
||||
--json '{
|
||||
"db": "mydb",
|
||||
"q": "SELECT * FROM information_schema.columns WHERE table_schema = '"'iox'"' AND table_name = '"'system_swap'"'",
|
||||
|
@ -120,7 +120,7 @@ To view recently executed queries, query the `queries` system table:
|
|||
|
||||
```bash
|
||||
curl "http://localhost:8181/api/v3/query_sql" \
|
||||
--header "Content-Type: application/json" \
|
||||
--header "Authorization: Bearer AUTH_TOKEN"
|
||||
--json '{
|
||||
"db": "mydb",
|
||||
"q": "SELECT * FROM system.queries LIMIT 2",
|
||||
|
|
|
@ -12,7 +12,7 @@ The mechanism for providing your token depends on the client you use to interact
|
|||
{{< tabs-wrapper >}}
|
||||
{{% tabs %}}
|
||||
[influxdb3 CLI](#influxdb3-cli-auth)
|
||||
[cURL](#curl-auth)
|
||||
[HTTP API](#http-api-auth)
|
||||
{{% /tabs %}}
|
||||
{{% tab-content %}}
|
||||
|
||||
|
@ -49,6 +49,12 @@ authorization token to all `influxdb3` commands.
|
|||
{{% /tab-content %}}
|
||||
{{% tab-content %}}
|
||||
|
||||
To authenticate directly to the HTTP API, you can include your authorization token in the HTTP Authorization header of your request.
|
||||
The `Authorization: Bearer AUTH_TOKEN` scheme works with all HTTP API endpoints that require authentication.
|
||||
|
||||
The following examples use `curl` to show to authenticate to the HTTP API.
|
||||
|
||||
|
||||
{{% code-placeholders "YOUR_AUTH_TOKEN" %}}
|
||||
```bash
|
||||
# Add your token to the HTTP Authorization header
|
||||
|
@ -57,14 +63,46 @@ curl "http://{{< influxdb/host >}}/api/v3/query_sql" \
|
|||
--data-urlencode "db=DATABASE_NAME" \
|
||||
--data-urlencode "q=SELECT * FROM 'DATABASE_NAME' WHERE time > now() - INTERVAL '10 minutes'"
|
||||
```
|
||||
{{% /code-placeholders %}}
|
||||
|
||||
### Authenticate using v1 and v2 compatibility
|
||||
|
||||
```bash
|
||||
# Token scheme with v2 /api/v2/write
|
||||
curl http://localhost:8181/api/v2/write\?bucket\=DATABASE_NAME \
|
||||
--header "Authorization: Token YOUR_AUTH_TOKEN" \
|
||||
--data-raw "home,room=Kitchen temp=23.5 1622547800"
|
||||
```
|
||||
|
||||
```bash
|
||||
# Basic scheme with v1 /write
|
||||
# Username is ignored, but required for the request
|
||||
# Password is your auth token encoded in base64
|
||||
curl "http://localhost:8181/write?db=DATABASE_NAME" \
|
||||
--user "admin:YOUR_AUTH_TOKEN" \
|
||||
--data-raw "home,room=Kitchen temp=23.5 1622547800"
|
||||
```
|
||||
|
||||
```bash
|
||||
# URL auth parameters with v1 /write
|
||||
# Username is ignored, but required for the request
|
||||
curl "http://localhost:8181/write?db=DATABASE_NAME&u=admin&p=YOUR_AUTH_TOKEN" \
|
||||
--data-raw "home,room=Kitchen temp=23.5 1622547800"
|
||||
```
|
||||
{{% /code-placeholders %}}
|
||||
{{% /tab-content %}}
|
||||
{{< /tabs-wrapper >}}
|
||||
|
||||
Replace the following with your values:
|
||||
|
||||
- {{% code-placeholder-key %}}`YOUR_AUTH_TOKEN`{{% /code-placeholder-key %}}: your {{% token-link %}}
|
||||
- {{% code-placeholder-key %}}`DATABASE_NAME`{{% /code-placeholder-key %}}: the name of the database you want to query
|
||||
- {{% code-placeholder-key %}}`DATABASE_NAME`{{% /code-placeholder-key %}}: the name of the [database](/influxdb3/version/databases) you want to query
|
||||
|
||||
To use tokens with other clients for {{< product-name >}},
|
||||
see the client-specific documentation:
|
||||
|
||||
- [InfluxDB 3 Explorer](/influxdb3/explorer/)
|
||||
- [InfluxDB client libraries](/influxdb3/version/reference/client-libraries/)
|
||||
- [Telegraf](/telegraf/v1/)
|
||||
- [Grafana](/influxdb3/version/visualize-data/grafana/)
|
||||
|
||||
{{< children hlevel="h2" readmore=true hr=true >}}
|
||||
|
|
|
@ -35,7 +35,8 @@ Include the following parameters:
|
|||
The following example sends an HTTP `GET` request with a URL-encoded SQL query:
|
||||
|
||||
```bash
|
||||
curl -v "http://{{< influxdb/host >}}/api/v3/query_sql?db=servers&q=select+*+from+cpu+limit+5"
|
||||
curl "http://{{< influxdb/host >}}/api/v3/query_sql?db=servers&q=select+*+from+cpu+limit+5" \
|
||||
--header "Authorization: Bearer AUTH_TOKEN"
|
||||
```
|
||||
|
||||
### Example: Query passing JSON parameters
|
||||
|
@ -44,7 +45,8 @@ The following example sends an HTTP `POST` request with parameters in a JSON pay
|
|||
|
||||
```bash
|
||||
curl http://{{< influxdb/host >}}/api/v3/query_sql \
|
||||
--data '{"db": "server", "q": "select * from cpu limit 5"}'
|
||||
--header "Authorization: Bearer AUTH_TOKEN"
|
||||
--json '{"db": "server", "q": "select * from cpu limit 5"}'
|
||||
```
|
||||
|
||||
### Query system information
|
||||
|
@ -71,7 +73,8 @@ tables (`"table_schema":"iox"`), system tables, and information schema tables
|
|||
for a database:
|
||||
|
||||
```bash
|
||||
curl "http://{{< influxdb/host >}}/api/v3/query_sql?db=mydb&format=jsonl&q=show%20tables"
|
||||
curl "http://{{< influxdb/host >}}/api/v3/query_sql?db=mydb&format=jsonl&q=show%20tables" \
|
||||
--header "Authorization: Bearer AUTH_TOKEN"
|
||||
```
|
||||
|
||||
The response body contains the following JSONL:
|
||||
|
@ -117,7 +120,7 @@ that surround field names._
|
|||
|
||||
```bash
|
||||
curl "http://localhost:8181/api/v3/query_sql" \
|
||||
--header "Content-Type: application/json" \
|
||||
--header "Authorization: Bearer AUTH_TOKEN" \
|
||||
--json '{
|
||||
"db": "mydb",
|
||||
"q": "SELECT * FROM information_schema.columns WHERE table_schema = '"'iox'"' AND table_name = '"'system_swap'"'",
|
||||
|
@ -144,7 +147,7 @@ To view recently executed queries, query the `queries` system table:
|
|||
|
||||
```bash
|
||||
curl "http://localhost:8181/api/v3/query_sql" \
|
||||
--header "Content-Type: application/json" \
|
||||
--header "Authorization: Bearer AUTH_TOKEN" \
|
||||
--json '{
|
||||
"db": "mydb",
|
||||
"q": "SELECT * FROM system.queries LIMIT 2",
|
||||
|
@ -180,7 +183,8 @@ Include the following parameters:
|
|||
The following example sends an HTTP `GET` request with a URL-encoded InfluxQL query:
|
||||
|
||||
```bash
|
||||
curl -v "http://{{< influxdb/host >}}/api/v3/query_influxql?db=servers&q=select+*+from+cpu+limit+5"
|
||||
curl "http://{{< influxdb/host >}}/api/v3/query_influxql?db=servers&q=select+*+from+cpu+limit+5" \
|
||||
--header "Authorization: Bearer AUTH_TOKEN"
|
||||
```
|
||||
|
||||
### Example: Query passing JSON parameters
|
||||
|
@ -189,5 +193,6 @@ The following example sends an HTTP `POST` request with parameters in a JSON pay
|
|||
|
||||
```bash
|
||||
curl http://{{< influxdb/host >}}/api/v3/query_influxql \
|
||||
--data '{"db": "server", "q": "select * from cpu limit 5"}'
|
||||
--header "Authorization: Bearer AUTH_TOKEN" \
|
||||
--json '{"db": "server", "q": "select * from cpu limit 5"}'
|
||||
```
|
Loading…
Reference in New Issue