1
votes

I have exported the dashboard in json format.

I want to import the json file manually to create the same dashboard in new grafana instance.

While googling i got some related information but finding difficulties to implement successfully.

From the site Grafana API link i got the code snippet like,

POST /api/dashboards/db HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

{ “dashboard”: { “id”: null, “uid”: null, “title”: “Production Overview”, “tags”: [ “templated” ], “timezone”: “browser”, “schemaVersion”: 16, “version”: 0 }, “folderId”: 0, “overwrite”: false }

The above code snippet looks like we can create new dashboard with existing json file but i have no idea of how to implement this code snippet successfully.

Somebody guide me how to achieve this?

2

2 Answers

2
votes

There are two techniques to copy the current dashboard - if you want to export this

  1. Go to Current Grafana Dashboard
  2. Select the Share button on the top enter image description here
  3. Select the Export Button and Copy the JSON or save it as JSON enter image description here

Create new Grafana dashboard and copy this JSON model to

  • Click on the Setting button on the top
  • Click on JSON Model - from left panel enter image description here
  • Past the JSON & Save the dashboard and run

Please let me know if you have any issue.

1
votes

I found and answer to your question - how to import a dashboard in grafana by api - in this post on the community board of Grafana:

https://community.grafana.com/t/how-create-dashboard-and-panel-via-api/10947

Haven't tried this out yet though (we are planning on doing something like this as well).

I will quote the original question in this post:

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? the part of the message that explains the answer:

And the response that contains the answer to the question:

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)"