From 1affa1cddb2884b6e9b76b394925c1c67a6a8da9 Mon Sep 17 00:00:00 2001 From: Daniel Goldman Date: Sun, 29 Oct 2023 17:07:48 -0400 Subject: [PATCH] Doc: Selecting Organizations --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 37e404d..aa2ce60 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,25 @@ grafana = GrafanaApi.from_env() Please note that, on top of the specific examples above, the object obtained by `credential` can be an arbitrary `requests.auth.AuthBase` instance. +## Selecting Organizations + +If the Grafana API is authenticated as a user (for example, with HTTP Basic Authentication), +it will use the user's current organization context. +That context can be changed with the `GrafanaApi.user.switch_actual_user_organisation` function. + +```python +grafana.user.switch_actual_user_organisation(1) +``` + +An instance of `GrafanaApi` can also be bound to a single organization with the `organization_id` parameter, +ensuring that all requests will be made to that organization. +This parameter will cause `GrafanaClient` to use the [X-Grafana-Org-Id header]. + +```python +grafana = GrafanaApi(..., organization_id=1) +``` + +API Tokens are bound to a single organization, so the `organization_id` parameter does not need to be specified. ## Timeout settings @@ -294,5 +313,6 @@ follow the [development documentation]. [future maintenance of `grafana_api`]: https://github.com/m0nhawk/grafana_api/issues/88 [grafana_api]: https://github.com/m0nhawk/grafana_api [Grafana Admin API]: https://grafana.com/docs/grafana/latest/http_api/admin/ +[X-Grafana-Org-Id header]: https://grafana.com/docs/grafana/latest/developers/http_api/auth/#x-grafana-org-id-header [Grafana HTTP API reference]: https://grafana.com/docs/grafana/latest/http_api/ [LICENSE]: https://github.com/panodata/grafana-client/blob/main/LICENSE