Hello together,
I would like to achieve that the refresh of my grafana dashboard is triggered by python code. This way I can make sure that always the latest data is displayed on the dashboard without setting a very short automatic refresh interval of for example one second.
My idea was to look for a corresponding API endpoint from Grafana, which I can then address from the Python script. Unfortunately I could not find a suitable endpoint for this.
ChatGPT suggested me the following code:
import requests
def refresh_dashboard(api_key, dashboard_uid):
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
url = f'http://your-grafana-instance/api/dashboards/uid/{dashboard_uid}/refresh'
response = requests.post(url, headers=headers)
if response.status_code == 200:
print('Dashboard refresh successful')
else:
print(f'Dashboard refresh failed. Status code: {response.status_code}')
# Example usage
api_key = 'your-api-key'
dashboard_uid = 'your-dashboard-uid'
refresh_dashboard(api_key, dashboard_uid)
However, the URL used is not so included in the Swagger documentation of grafana, so I doubt the existence of the endpoint.
However, the suggested code works when using as URL an endpoint specified in the Swagger documentation.
Has anyone ever had a similar use case and a suitable solution suggestion for it?
Grafana Version 9.5.1
Docker 23.0.2 on Ubuntu 22.04.2 LTS