How create Dashboard and Panel via API

api
#1

Hi All,

I know how to create a dashboard via API but I don’t find instructions to how to create panels within that dashboard still via API. Any idea?

#2

There is no API for panels only.

You can create & update dashboards using this API
http://docs.grafana.org/http_api/dashboard/#create-update-dashboard

#3

I saw that :slight_smile: But what is the point to create an empty dashboard?

#4

The panels need to be defined within the JSON that you submit in your POST request.

The example in the docs doesn’t spell this out, beyond

dashboard – The complete dashboard model

To get hands-on with this, you can (1) create a new dashboard with some panels manually, (2) export that dashboard’s definition as JSON, (3) put the exported dashboard definition inside the “dashboard” field of a new JSON object, (4) POST the resulting JSON object to the API endpoint. This will create a copy of your original dashboard. From there on, you can edit the JSON model you’re posting in order to modify or add any panels you desire.

So to your original question, if you want to add a panel to an existing dashboard you can obtain its definition via the API, add the panel to the JSON object, and push the updated model. (keep the same id/uid and set "overwrite": true)

Error 422 Unprocessable Entity - API Update Dashboard
#5

After I obtain dashboard definition via the API, I push the updated model. When I do this, the dashboard goes to another folder. Do you know why this happens and how to fix it?