External snapshot created via API, but no data is shown, error "Invalid dashboard UID in annotation request"

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

  • What are you trying to achieve?
    Create an external snapshot of a dashboard via API

  • How are you trying to achieve it?

def new_snapshot(url):

url_db = url.split("/")
uid = url_db[4]
db_get = get_db_uid(uid, grafana_server, grafana_api_key)
dashboard = db_get ["dashboard"]
ss_name = dashboard["title"] + " Snapshot"
dashboard_json = get_snapshot_db_json(dashboard, ss_name, True, "buy12345", "boys12345" )
result = create_snapshot(dashboard_json, grafana_server, grafana_api_key)
return result["url"]

def get_db_uid(uid, server, api_key, verify=True):

headers = {'Authorization': f"Bearer {api_key}", 'Content-Type': 'application/json'}

try:
    r = requests.get(f"https://{server}/api/dashboards/uid/{uid}", headers=headers, verify=verify)
    print(f"{r.status_code} ")
    return r.json()

def get_snapshot_db_json(dashboard, name, external=True, key=“abc123456”, deleteKey=“def987654”):

if external:
    return json.dumps(
        {
        "dashboard": dashboard,
        "name": name,
        "external": external,
        "key": key,
        "deleteKey": deleteKey
        }, sort_keys=True, indent=2)
else:
    return json.dumps(
        {
        "dashboard": dashboard,
        "name": name,
        "external": external,
        }, sort_keys=True, indent=2)

def create_snapshot(json, server, api_key, verify=True):

headers = {'Authorization': f"Bearer {api_key}", 'Content-Type': 'application/json'}

try:
    r = requests.post(f"https://{server}/api/snapshots", data=json, headers=headers, verify=verify)
    print(f"{r.status_code} - {r.content}")
    return r.json()

For both internal and external snapshot, new_snapshot(url) return a success URL to the snapshot.

  • What happened?

For internal snapshot, URL can be accessed, with correct datas.
For external snapshot, URL can be accessed, all panes on dashboard can be shown, but all panes shown no data. There is an error msg of “Invalid dashboard UID in annotation request”

Here is the URL returned from above py code:
https://snapshots.raintank.io/dashboard/snapshot/buy12345

  • What did you expect to happen?

External snapshot should have the data shown. If I use Web GUI to create the external snapshot, I can access with correct data. But with API, the dashboard with panes can be shown, but there is no data.

  • Can you copy/paste the configuration(s) that you are having problems with?

See above py.

dashboard detail is getting from API, and annotations/list is an empty list.

    "annotations": {
      "list": []
    },

If I use GUI to access the dashboard JSON, the annotations/list is as below:

  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

“Invalid dashboard UID in annotation request” in the top-right corner of the dashboard

  • Did you follow any online instructions? If so, what is the URL?
2 Likes

I have exact same problem