Docs: deprecate API key reference docs and update API tutorial to use service accounts (#77429)

* deprecate API key reference docs and update API tutorial to use service accounts

* Update create-api-tokens-for-org.md
This commit is contained in:
Ieva
2023-10-31 13:29:08 +00:00
committed by GitHub
parent e67485de30
commit 9c47161c14
3 changed files with 79 additions and 72 deletions

View File

@ -29,13 +29,59 @@ Starting from version 9.1, there is also a [OpenAPI v3 specification](https://ed
Users can browser and try out both via the Swagger UI editor (served by the grafana server) by navigating to `/swagger-ui` and `/openapi3` respectively.
## Authenticating API requests
You can authenticate requests using basic auth, a service account token or a session cookie (acquired using regular login or OAuth).
### Basic Auth
If basic auth is enabled (it is enabled by default), then you can authenticate your HTTP request via
standard basic auth. Basic auth will also authenticate LDAP users.
curl example:
```bash
curl http://admin:admin@localhost:3000/api/org
{"id":1,"name":"Main Org."}
```
### Service Account Token
To create a service account token, click on **Administration** in the left-side menu, and then **Service Accounts**.
For more information on how to use service account tokens, refer to the [Service Accounts]({{< relref "../../administration/service-accounts/" >}}) documentation.
You use the token in all requests in the `Authorization` header, like this:
**Example**:
```http
GET http://your.grafana.com/api/dashboards/db/mydash HTTP/1.1
Accept: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```
The `Authorization` header value should be `Bearer <your service account token>`.
## X-Grafana-Org-Id Header
**X-Grafana-Org-Id** is an optional property that specifies the organization to which the action is applied. If it is not set, the created key belongs to the current context org. Use this header in all requests except those regarding admin.
**Example Request**:
```http
GET /api/org/ HTTP/1.1
Accept: application/json
Content-Type: application/json
X-Grafana-Org-Id: 2
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```
## HTTP APIs
- [Admin API]({{< relref "admin/" >}})
- [Alerting API (unstable)](https://editor.swagger.io/?url=https://raw.githubusercontent.com/grafana/grafana/main/pkg/services/ngalert/api/tooling/post.json)
- [Alerting Provisioning API]({{< relref "alerting_provisioning/" >}})
- [Annotations API]({{< relref "annotations/" >}})
- [Authentication API]({{< relref "auth/" >}})
- [Correlations API]({{< relref "correlations/" >}})
- [Dashboard API]({{< relref "dashboard/" >}})
- [Dashboard Permissions API]({{< relref "dashboard_permissions/" >}})
@ -59,6 +105,7 @@ Users can browser and try out both via the Swagger UI editor (served by the graf
- [Alerting Notification Channels API]({{< relref "alerting_notification_channels/" >}})
- [Alerting API]({{< relref "alerting/" >}})
- [Authentication API]({{< relref "auth/" >}})
## Grafana Enterprise HTTP APIs