Round trip dashboard maintenance using the Dashboard Import REST API

  • What Grafana version and what operating system are you using?

10.0.1 on Rocky 9.6

  • What are you trying to achieve?

Figure out best way to allow ‘round-trip’ dashboard maintenance via the API - create dashboards from json files stored in source control, edit them live, export the json in a format it can go back into the repo.

  • How are you trying to achieve it?

I have had success mangling the output of either the dashboard GET call (api/dashboards/uid/) or exporting from the GUI (I believe its the API under the covers anyway, but the outputs are quite different) and then deleting and re-creating dashboards (api/dashboards/db). But there is quite a lot of faffing with json, removing the dashboard UID, potentially updating datasources etc. I then came across the following github discussion where torkelo suggests there is a Dashboard Import API which is designed to be used to allow import of GUI-export format files. He also suggests that required params (e.g. new local datasource in import destination etc.) can be added to the POST operation. However, he only supplies a tiny screenshot and does not link to the docs.

  • Questions in a nutshell:

    • Can anyone point at documentation for Dashboard Import API? I cannot find it at any version level in the docs.
    • Can anyone point at a detailed example of using it?
    • Does anyone have a good overview of a way to carry out ‘round-trip’ dashboard creation via the API and/or GUI? (file-based provisioning does not fully meet our requirement because the dashboard json is too large to push into the configMap of some of our k8s installations)

Hi - appreciate the response but neither of these articles addresses my questions.

I have updated my question title to better target this.

No responses on the specific question of the “Dashboard Import” API but the following workflow seems to do what I need - it may not be optimal!

  • many any changes to dashboards in GUI as usual
  • take a ‘non-sharing’ export of the json with the Share button in the GUI
  • set uid to “null” in the resulting json or simply delete it
  • overwrite the json in my repo with new copy
  • on each deploy, delete all dashboards with DELETE method /api/dashboards/uid/
  • and recreate with e.g.
  ansible.builtin.uri:
    url: http://localhost:3000/api/dashboards/import
    method: POST
    headers:
      Content-Type: application/json
      Accept: application/json
      Authorization: "Bearer {{ serviceaccount_token }}"
    body_format: json
    body: "{{ lookup('ansible.builtin.file',item) }}"
    return_content: yes
  with_items:
    - dashboard_timings.json
    - dashboard_vm_estate.json

To avoid the issue of variable datasource names, I have simply provisioned these to have the same uids across all environment.

Thx