How to get JSON Model via API?

I’m using Grafana v8.3.3 (30bb7a93ca) on Linux and I’m trying to automate exporting my dashboards to json files for automation.

I’d eventually use these to import dashboards on a fresh instance using /etc/grafana/provisioning/dashboards

I’m able to pull the dashboards out using a call to /api/dashboards/uid/$uid but the JSON output is different from that which I can copy from the web UI’s JSON Model tab in the dashboard’s settings.

When I try to provision the API output using the provisioning directory, the dashboard gets created but is completely empty / broken.

When I provision the API output using the JSON Model that I’ve copied and pasted, it works great.

So, ultimately - Is there any way to get the same output as “JSON Model” via the API, or is there something else I can use to try to find out why the api-exported JSON doesn’t work on provisioning?

Here’s the error message when I try to import the JSON that was provided by the API:

t=2021-12-25T21:05:40+0000 lvl=eror msg="failed to load dashboard from " logger=provisioning.dashboard type=file name="local provisioning folder" file=/etc/grafana/provisioning/dashboards/api.json error="Dashboard title cannot be empty"

Ah - I think I’ve figured out how to fix it (although I still think the API’s output not being provisionable is a bit buggy / not a nice user experience)

The details are here: Dashboard provisioning error: "Dashboard title cannot be empty" · Issue #13029 · grafana/grafana · GitHub

Basically you need to use jq to massage the API output json into the format that the provisioner expects:

(api curl) | jq '.dashboard.id = null' | jq '.dashboard'