Import Panels and Graphs Programatically

I can create dashboards using the http api (http://docs.grafana.org/http_api/dashboard/#create-update-dashboard) but how can I programatically add panels and graphs to it?

Is there a way to import the contents of a dashboard using an api or something else without manual steps?

Not sure what you mean. The dashboard api allows you to save a dashboard, the dashboard json includes all the panels (graphs & options & positions). So just build that programmatically and use the dashboard api to save it.

Ah yea I see that now. The docs didn’t go into much detail on the structure of the panels json but I figured out viewing the dashboard I’ve created as json this maps to the “dashboards” attribute in the API call as long as I remove the id and uid.

{
  "dashboard": <insert data from "settings > View JSON">,
  "overwrite": false
}

Hi,

I’m a bit confuse because i’m trying to build Dashboards using the API but i’m having only blank Dashboards with no panels. I would like to automate all the process of building Dashboards using the API but i’m not sure witch endpoint i shoud use. Should i go through the update_dashboard API endpoint or the scripted dashboard endpoint ?
The scripted technique seems like it dosen’t allow to save automatically a dashboard. Any advise please ?
Best regards

Hi @amd,

This is the API endpoint to create a dashboard:
http://docs.grafana.org/http_api/dashboard/#create-update-dashboard

If you specify a dashboard ID in the POST request, the existing dashboard with that ID will be updated with the JSON data you supply as the “dashboard” value.

I don’t know what you mean by “scripted dashboard endpoint”. I think there is just one API endpoint.

Hi @adeverteuil,

thanks you for your reply. I succeed creating dashboard using the API endpoint. In fact there is another endpoint that allow dashboards injection with JavaScript :
http://docs.grafana.org/reference/scripting/
I dont know in wich situation it could be useful.
I was wondering, Is it possible to create multiple dashboards with one request ?

Hi @amd,

The HTTP API does not have a method to create multiple dashboards in a single call.

Here are examples of scripted dashboards:
https://github.com/grafana/grafana/tree/master/public/dashboards
This feature allows users to build the dashboard JSON objects on-the-fly from URL parameters and pass it to Grafana instead of using a static JSON string.
Also refer to the dashboard JSON model:
http://docs.grafana.org/reference/dashboard/
Another way to explain this feature, is it allows you to have templating at the dashboard level, not only at the Data Source query level. You could use it to maintain several related dashboards in a single javascript program, like different layouts of the same panels for different teams or displays.

You may also be interested in the “Provisioning” method of creating dashboards:
http://docs.grafana.org/administration/provisioning/#dashboards