7

I'm trying to overwrite existing grafana dashboard via API, like this :

curl -X POST -H "Content-Type: application/json" "https://api_key:xxx/api/dashboards/db" -d @test.json

And i'm facing an issue with versioning, cannot overwrite the same dashboard with my json :

{"message":"The dashboard has been changed by someone else","status":"version-mismatch"}⏎

Is there a way to avoid this and force overwriting ?

Thanks !

user2462699
  • 429
  • 2
  • 8
  • 17

2 Answers2

11

That really depends what is in your test.json file. I expect correct dashboard model, so you just need to add a few fields to the top level, e.g.:

"overwrite": true,
"message": "my saved message, which will be available in the version history"

See API doc - https://grafana.com/docs/grafana/latest/http_api/dashboard/#create-update-dashboard

Jan Garaj
  • 25,598
  • 3
  • 38
  • 59
  • 1
    damn.. i was placing "overwrite": true in the meta part, not at the top level... is there a way to put this line automatically in the json model ? i'm placing it manually after export and this is not very convenient... – user2462699 May 27 '20 at 08:47
  • @user2462699 I use python, where it is piece of cake. You may try to play with jq./sed/... – Jan Garaj May 27 '20 at 09:45
  • @JanGaraj can you share any python code snippet/example for this? would be great if it uses [grafanlib](https://github.com/weaveworks/grafanalib). – aquaman Oct 25 '21 at 02:57
3

Increment version field one time or several.

 "uid": "hDfaY-fGk",
  "version": 20            <-this one. Make it 21, 22, 23
}