Skip to content

Commit cb4d1f2

Browse files
lilatomicamotl
authored andcommitted
Doc: Selecting Organizations
1 parent d87c9a8 commit cb4d1f2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ grafana = GrafanaApi.from_env()
135135
Please note that, on top of the specific examples above, the object obtained by
136136
`credential` can be an arbitrary `requests.auth.AuthBase` instance.
137137

138+
## Selecting Organizations
139+
140+
If the Grafana API is authenticated as a user (for example, with HTTP Basic Authentication),
141+
it will use the user's current organization context.
142+
That context can be changed with the `GrafanaApi.user.switch_actual_user_organisation` function.
143+
144+
```python
145+
grafana.user.switch_actual_user_organisation(1)
146+
```
147+
148+
An instance of `GrafanaApi` can also be bound to a single organization with the `organization_id` parameter,
149+
ensuring that all requests will be made to that organization.
150+
This parameter will cause `GrafanaClient` to use the [X-Grafana-Org-Id header].
151+
152+
```python
153+
grafana = GrafanaApi(..., organization_id=1)
154+
```
155+
156+
API Tokens are bound to a single organization, so the `organization_id` parameter does not need to be specified.
138157

139158
## Timeout settings
140159

@@ -294,5 +313,6 @@ follow the [development documentation].
294313
[future maintenance of `grafana_api`]: https://github.com/m0nhawk/grafana_api/issues/88
295314
[grafana_api]: https://github.com/m0nhawk/grafana_api
296315
[Grafana Admin API]: https://grafana.com/docs/grafana/latest/http_api/admin/
316+
[X-Grafana-Org-Id header]: https://grafana.com/docs/grafana/latest/developers/http_api/auth/#x-grafana-org-id-header
297317
[Grafana HTTP API reference]: https://grafana.com/docs/grafana/latest/http_api/
298318
[LICENSE]: https://github.com/panodata/grafana-client/blob/main/LICENSE

0 commit comments

Comments
 (0)