Grafana overwrite existing dashboard via API
Asked Answered
I

2

8

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 !

Ilia answered 26/5, 2020 at 15:31 Comment(0)
S
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

Starknaked answered 26/5, 2020 at 18:8 Comment(3)
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...Ilia
@Ilia I use python, where it is piece of cake. You may try to play with jq./sed/...Starknaked
@JanGaraj can you share any python code snippet/example for this? would be great if it uses grafanlib.Ashford
H
3

Increment version field one time or several.

 "uid": "hDfaY-fGk",
  "version": 20            <-this one. Make it 21, 22, 23
}
Heartless answered 30/11, 2021 at 16:12 Comment(2)
The right answer.Jeannajeanne
Doesn't appear to work for me. Still the same message.Transubstantiate

© 2022 - 2024 — McMap. All rights reserved.