Skip to content

Commit 6041afb

Browse files
committed
chore(influxdb3): Add auth header to API request samples
1 parent 14a6f40 commit 6041afb

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

content/shared/influxdb3-admin/query-system-data/_index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ that surround field names._
9393

9494
```bash
9595
curl "http://localhost:8181/api/v3/query_sql" \
96-
--header "Content-Type: application/json" \
96+
--header "Authorization: Bearer AUTH_TOKEN" \
9797
--json '{
9898
"db": "mydb",
9999
"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:
120120

121121
```bash
122122
curl "http://localhost:8181/api/v3/query_sql" \
123-
--header "Content-Type: application/json" \
123+
--header "Authorization: Bearer AUTH_TOKEN"
124124
--json '{
125125
"db": "mydb",
126126
"q": "SELECT * FROM system.queries LIMIT 2",

content/shared/influxdb3-admin/tokens/_index.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The mechanism for providing your token depends on the client you use to interact
1212
{{< tabs-wrapper >}}
1313
{{% tabs %}}
1414
[influxdb3 CLI](#influxdb3-cli-auth)
15-
[cURL](#curl-auth)
15+
[HTTP API](#http-api-auth)
1616
{{% /tabs %}}
1717
{{% tab-content %}}
1818

@@ -49,6 +49,12 @@ authorization token to all `influxdb3` commands.
4949
{{% /tab-content %}}
5050
{{% tab-content %}}
5151

52+
To authenticate directly to the HTTP API, you can include your authorization token in the HTTP Authorization header of your request.
53+
The `Authorization: Bearer AUTH_TOKEN` scheme works with all HTTP API endpoints that require authentication.
54+
55+
The following examples use `curl` to show to authenticate to the HTTP API.
56+
57+
5258
{{% code-placeholders "YOUR_AUTH_TOKEN" %}}
5359
```bash
5460
# Add your token to the HTTP Authorization header
@@ -57,14 +63,46 @@ curl "http://{{< influxdb/host >}}/api/v3/query_sql" \
5763
--data-urlencode "db=DATABASE_NAME" \
5864
--data-urlencode "q=SELECT * FROM 'DATABASE_NAME' WHERE time > now() - INTERVAL '10 minutes'"
5965
```
60-
{{% /code-placeholders %}}
6166

67+
### Authenticate using v1 and v2 compatibility
68+
69+
```bash
70+
# Token scheme with v2 /api/v2/write
71+
curl http://localhost:8181/api/v2/write\?bucket\=DATABASE_NAME \
72+
--header "Authorization: Token YOUR_AUTH_TOKEN" \
73+
--data-raw "home,room=Kitchen temp=23.5 1622547800"
74+
```
75+
76+
```bash
77+
# Basic scheme with v1 /write
78+
# Username is ignored, but required for the request
79+
# Password is your auth token encoded in base64
80+
curl "http://localhost:8181/write?db=DATABASE_NAME" \
81+
--user "admin:YOUR_AUTH_TOKEN" \
82+
--data-raw "home,room=Kitchen temp=23.5 1622547800"
83+
```
84+
85+
```bash
86+
# URL auth parameters with v1 /write
87+
# Username is ignored, but required for the request
88+
curl "http://localhost:8181/write?db=DATABASE_NAME&u=admin&p=YOUR_AUTH_TOKEN" \
89+
--data-raw "home,room=Kitchen temp=23.5 1622547800"
90+
```
91+
{{% /code-placeholders %}}
6292
{{% /tab-content %}}
6393
{{< /tabs-wrapper >}}
6494

6595
Replace the following with your values:
6696

6797
- {{% code-placeholder-key %}}`YOUR_AUTH_TOKEN`{{% /code-placeholder-key %}}: your {{% token-link %}}
68-
- {{% code-placeholder-key %}}`DATABASE_NAME`{{% /code-placeholder-key %}}: the name of the database you want to query
98+
- {{% code-placeholder-key %}}`DATABASE_NAME`{{% /code-placeholder-key %}}: the name of the [database](/influxdb3/version/databases) you want to query
99+
100+
To use tokens with other clients for {{< product-name >}},
101+
see the client-specific documentation:
102+
103+
- [InfluxDB 3 Explorer](/influxdb3/explorer/)
104+
- [InfluxDB client libraries](/influxdb3/version/reference/client-libraries/)
105+
- [Telegraf](/telegraf/v1/)
106+
- [Grafana](/influxdb3/version/visualize-data/grafana/)
69107

70108
{{< children hlevel="h2" readmore=true hr=true >}}

content/shared/influxdb3-query-guides/execute-queries/influxdb3-api.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Include the following parameters:
3535
The following example sends an HTTP `GET` request with a URL-encoded SQL query:
3636

3737
```bash
38-
curl -v "http://{{< influxdb/host >}}/api/v3/query_sql?db=servers&q=select+*+from+cpu+limit+5"
38+
curl "http://{{< influxdb/host >}}/api/v3/query_sql?db=servers&q=select+*+from+cpu+limit+5" \
39+
--header "Authorization: Bearer AUTH_TOKEN"
3940
```
4041

4142
### Example: Query passing JSON parameters
@@ -44,7 +45,8 @@ The following example sends an HTTP `POST` request with parameters in a JSON pay
4445

4546
```bash
4647
curl http://{{< influxdb/host >}}/api/v3/query_sql \
47-
--data '{"db": "server", "q": "select * from cpu limit 5"}'
48+
--header "Authorization: Bearer AUTH_TOKEN"
49+
--json '{"db": "server", "q": "select * from cpu limit 5"}'
4850
```
4951

5052
### Query system information
@@ -71,7 +73,8 @@ tables (`"table_schema":"iox"`), system tables, and information schema tables
7173
for a database:
7274

7375
```bash
74-
curl "http://{{< influxdb/host >}}/api/v3/query_sql?db=mydb&format=jsonl&q=show%20tables"
76+
curl "http://{{< influxdb/host >}}/api/v3/query_sql?db=mydb&format=jsonl&q=show%20tables" \
77+
--header "Authorization: Bearer AUTH_TOKEN"
7578
```
7679

7780
The response body contains the following JSONL:
@@ -117,7 +120,7 @@ that surround field names._
117120

118121
```bash
119122
curl "http://localhost:8181/api/v3/query_sql" \
120-
--header "Content-Type: application/json" \
123+
--header "Authorization: Bearer AUTH_TOKEN" \
121124
--json '{
122125
"db": "mydb",
123126
"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:
144147

145148
```bash
146149
curl "http://localhost:8181/api/v3/query_sql" \
147-
--header "Content-Type: application/json" \
150+
--header "Authorization: Bearer AUTH_TOKEN" \
148151
--json '{
149152
"db": "mydb",
150153
"q": "SELECT * FROM system.queries LIMIT 2",
@@ -180,7 +183,8 @@ Include the following parameters:
180183
The following example sends an HTTP `GET` request with a URL-encoded InfluxQL query:
181184

182185
```bash
183-
curl -v "http://{{< influxdb/host >}}/api/v3/query_influxql?db=servers&q=select+*+from+cpu+limit+5"
186+
curl "http://{{< influxdb/host >}}/api/v3/query_influxql?db=servers&q=select+*+from+cpu+limit+5" \
187+
--header "Authorization: Bearer AUTH_TOKEN"
184188
```
185189

186190
### Example: Query passing JSON parameters
@@ -189,5 +193,6 @@ The following example sends an HTTP `POST` request with parameters in a JSON pay
189193

190194
```bash
191195
curl http://{{< influxdb/host >}}/api/v3/query_influxql \
192-
--data '{"db": "server", "q": "select * from cpu limit 5"}'
196+
--header "Authorization: Bearer AUTH_TOKEN" \
197+
--json '{"db": "server", "q": "select * from cpu limit 5"}'
193198
```

0 commit comments

Comments
 (0)