Automate Grafana dashboard migration using Python API

Hi,

I’m trying to use Python API to automatically Export existing Grafana dashboards from a source URL / Folder and Import them to destination URL / Folder. Providing you code snippet below for the same where I’m getting ‘404’ response (even with requests.put). Can you tell me where I’m going wrong?

import requests
import json

url_source = ‘URL_SOURCE/api/’
headers_source = {
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’,
‘Authorization’: ‘API_KEY_SOURCE’
}

url_dest = ‘URL_DESTINATION/api/’
headers_dest = {
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’,
‘Authorization’: ‘API_KEY_DESTINATION’
}

data = requests.get(url_source + ‘dashboards/uid/xyzABCD’, headers=headers_source).json()

db_data = {
“dashboard”: data[‘dashboard’],
“folderId”: data[‘meta’][‘folderId’],
“folderUid”: data[‘meta’][‘folderUid’],
“message”: “Imported DB xyzABCD to destination”,
“overwrite”: False
}

s = requests.post(url_dest + ‘dashboards/db’, headers=headers_dest, data = json.dumps(db_data), verify = False)
print(s.status_code)

I get dashboards with bash/curl GET like this

for db_uid in $(curl -s -k “${full_url}/api/search” | jq -r ..uid); do
db_json=$(curl -s -k “${full_url}/api/dashboards/uid/${db_uid}”)
done

so don’t POST, and what is dashboards/db ?