A dashboard, which was exported via API, is blank when I upload it manually

I exported one of my dashboards into a JSON file via the dashboard API [^0]:

curl -s -H "Authorization: Bearer $api_key" -X GET "$domain/api/dashboards/uid/$uid" | jq > dashboard.json

But it’s weird that when I try to upload it manually via the UI the dashboard is totally blank.

Did I do something wrong?

[^0] Dashboard HTTP API | Grafana documentation

You exported it from what version of grafana and imported it to what version?

Dashboard “export” API is not the same as UI export from. Just try to export the same dashboard via UI and then via API and compare outputs. They are similar, but they are not the same => you can’t mix API/UI exports/imports (at least not without additional transformation), because they use different models.

1 Like

Is there a good reason for this difference?

It would seem to me to be beneficial if either the two formats could be made to
be the same, or at least the one which requires less data could ignore the
additional data produced by the other. That way, at least one direction would
work.

I’m intrigued as to why two different methods of achieving what appears (at
least to the average user) to be the same thing are incompatible.

Antony.

API aproach is only GET dashboard (not “export” dashboard) = it will provide model, which is used by app itself (so you can see internal ids/uids there) - “internal” model = this model can be used only in that particular Grafana instance.

UI is a real dashboard export, which will transform internal model (e.g. replace internal ids/uids, remove sensitive details) so this output can be imported into another Grafana instance without any issue.

It will be nice to have API for dashboard export, but that API still doesn’t exist. Export feature is still implemented only in the UI - frontend.

BTW: @amotl made a feature for programatic dashboard export.

Hi Jangaraj and everyone else.
so when we export a dashboard using API and then export the same dashboard using UI, then of course they are different even they look similar.
but what if we get a dashboard using API and import the exact dashboard using API again? (in different instance)
there should not be any different right? (but actually is)
I know this topic is almost one year old, but faced with similar issue here.
I wrote a python script which using a get requests to get all the dashboards and then i do change all of the datasource uid and ids(original id, uid will not work on new instance if we import the same since those ids, uid not exists, so we have to give them the new id, uid, folderid ect which i captured from new instance) and then using requests.post to push them to new instance in the same script. but still the dashboards come empty.
so with that being said.
we are not able to use get request to get bulk dashbaords and use post requests to import them even updating all requirements such id, uid, folderid ect?

my issue got resolved and my dashboards all imported to the new instance.
for those who faced with similar issues in future, if you use api get and post request to export and import your dashboards from old instance to new instance you can do as follow.

  1. get the dashboard using requests. Get
  2. do not export them to any path, keep Json in memory.
  3. remove all “id” value and set as empty string
  4. find the folderUid of your new instance and add it to your func in post request in order to import them in a folder you want.
  5. replace the values of all datascource’s uid with a new uid you get from new instance.
  6. from json file you just need the part start from “dashboard” or “annotations”. remove the rest of them. you dont need meta, or folders …
  7. make sure the have the exact data source name in both instance. otherwise it will be empty dashboards.
  8. you don’t need to have the exact Grafana version. my old version was 8.5 and new was 9.5.7
    hope this helps anyone who interested to do export/import using api request.