I am trying to add a dashboard to a toy Grafana local installation to debug a dashboard and play on how to setup the c.i. on our server.
I try to load the dasboard using e.g.
curl --request POST \
--url http://localhost:3000/api/dashboards/db \
--header 'Authorization: Bearer <my key>' \
--header 'Content-Type: application/json' \
--data '{<the whole dashboard json code...>}'
but I get "Alert validation error: Data source used by alert rule not found, alertName=Persistence Queues alert, datasource=".
This makes sense, cause I have not localy the datasource, however it stops me from loading the dashboard and playing around with it on my toy server. If I use import, I can load the dashboard, even with errors (but my goal is to test the http api for c.i.).
Is there a way / server config setting that will allow me to create the dashboard via the http api, even without a valid alert?
The documented API with a POST to /api/dashboards/db
requires a different JSON format than the exported JSON model from the Grafana UI.
You can POST your JSON to /api/dashboards/import
in order to execute the same query as the UI does internally. Since this is not officially documented, expect the API to change in future versions of Grafana. Make sure that all metadata (e.g. title
, uid
, overwrite
-flag and folderId
) are set as you wish. Some of these parameters are normally shown in the UI while importing and get replaced before making the query to the API.
Example request:
curl -X POST http://localhost:3000/api/dashboards/import \
-H "Authorization: Bearer xyz" \
-H "Content-Type: application/json" \
-d '{"dashboard":{"annotations": ...,"title":"Test-Import","uid":"unique-id-abc",...},"overwrite":true,...,"folderId":0}'
Example response:
{"pluginId":"","title":"Test-Import","imported":true,"importedUri":"db/test-import","importedUrl":"/d/unique-id-abc/test-import","slug":"test-import","dashboardId":15,"folderId":0,"importedRevision":1,"revision":1,"description":"","path":"","removed":false}