Context Not Switching with API Calls After Organization Switch

Hello everyone,

I wanted to share a solution and an important clarification regarding the usage of Grafana API for fetching dashboards, which might be particularly useful if you are struggling with similar issues.

For several weeks, I encountered a problem where using a custom API endpoint provided by a plugin (api/plugins/myappplugin/resources/search-dashboards) consistently returned dashboard data from the wrong organization, not reflecting changes even after switching organizations. This was misleading and caused quite a bit of confusion.

The correct approach to fetch all dashboards related to the currently active organization, considering access controls and without crossing organization boundaries, is to use the standard Grafana API endpoint with proper authentication:

GET /api/search?type=dash-db
Authorization: Bearer [YourServiceAccountToken]

This method ensures that you are fetching data pertinent to the current organization context established by the service account’s token, especially important for those managing multiple organizations within Grafana.

I hope this helps anyone who might be facing similar issues and apologies for any confusion caused by previous discussions or examples.

1 Like