Open DerfOh opened 5 years ago
In my experience, top-level "id" property may also not exist at all. To change only the top-level id better use jq: (depending on the file structure)
jq '.id = null' some.json
jq '.dashboard.id = null' some.json
To wrap a dashboard, exported using a Grafana UI, in a structure that allows you to create/update it via the Grafana API, I am using this script:
for GRAFANA_DASHBOARD_FILE in *.json; do
jq '{dashboard: ., folderId:0, overwrite:true} | .dashboard.id = null' "${GRAFANA_DASHBOARD_FILE}" >"update-dashboards.json.tmp
curl "https://${GRAFANA_HOSTNAME}/api/dashboards/db" \
-u "${GRAFANA_CURL_CREDENTIALS}" \
-H "Content-Type: application/json" \
--data-binary "@update-dashboards.json.tmp"
echo ""
done
Looks like uid changed a bit over time. Currently with grafana 8.3.6, I had to make the following change in exporter.sh:
for dash in $(fetch_fields $KEY 'search?query=&' 'url'); do
#DB=$(echo ${dash}|sed 's,db/,,g').json
DB=${dash##*/}.json
base=${dash%/*}
uid=${base##*/}
echo $DB
curl -f -k -H "Authorization: Bearer ${KEY}" "${HOST}/api/dashboards/uid/${uid}" | jq 'del(.overwrite,.dashboard.version,.meta.created,.meta.createdBy,.meta.updated,.meta.updatedBy,.meta.expires,.meta.version)' > "$DIR/dashboards/$DB"
done
I tried "id": null but does not work for me , kindly help
Haven't tried this in a long while, what error message do you get, if any?
Haven't tried this in a long while, what error message do you get, if any?
Dashboard is created but empty data..
POST : https://XXXXXXXXXx/api/dashboards/import
{ "dashboard": { "id": null, "uid": "Polaris_123xx", "title": "pol_testt", "tags": [ "templated" ], "timezone": "browser", "refresh": "25s" },
... .. }, "time": { "from": "now-5m", "to": "now" }, "timepicker": {}, "timezone": "", "title": "Polaris_123", "uid": "Polaris_123xx", "version": 1, "weekStart": "", "overwrite": true
}
could have to do with the recent changes to metric names in grafana > 9.x, developers tried to anonymize them, had to edit panel JSON to fix back to readable metric names.
Hi,
I am using Grafana v10.1.2
I can change in matrix name ,
this is my updated template , i exported template from Grafana GUI , now i want exported template load through HTTP API([api/dashboards/import) but when i load this template and login into grafana GUI i can see just dashbaord name created and rest is empty.
quite hard to diagnose for me, sorry, hope someone else can help you.
Error received
Root Cause:
File export includes the 'id' of the dashboard. This needs to be set to 'null' in order to be imported.
Also see: https://community.grafana.com/t/unable-to-create-grafana-dashboard-through-api-but-working-through-ui-import-option-with-same-json-file/2470
Workaround:
Execute the following in the dashboards directory (works with GNU sed only)