Modifying Grafana dashboard permissions using HTTP API w/ an OrgId is not working for me

  • What Grafana version and what operating system are you using?
    Grafana v12.0.2

  • What are you trying to achieve?
    Using Grafana HTTP API to update a dashboard’s permissions when the dashboard is part of an org that is not the default org.

  • How are you trying to achieve it?
    POST to create dashboard
    send: b’POST /apis/dashboard.grafana.app/v1beta1/namespaces/org-196/dashboards HTTP/1.1\r\nHost: redacted\r\nUser-Agent: python-requests/2.29.0\r\nAccept-Encoding: gzip, deflate, br\r\nAccept: /\r\nConnection: keep-alive\r\nAuthorization: Bearer redacted\r\nContent-Length: 8967\r\n\r\n’
    send: b’{“metadata”: {“name”: “redacted”} …
    reply: ‘HTTP/1.1 201 Created\r\n’

    POST to modify permissions of dashboard
    send: b’POST /api/dashboards/uid//permissions?orgId=196HTTP/1.1\r\nHost: redacted\r\nUser-Agent: python-requests/2.29.0\r\nAccept-Encoding: gzip, deflate, br\r\nAccept: /\r\nConnection: keep-alive\r\nAuthorization: Bearer redacted\r\nContent-Length: 48\r\n\r\n’
    send: b’{“items”: [{“role”: “Viewer”, “permission”: 1}]}’
    reply: ‘HTTP/1.1 400 Bad Request\r\n’

    GET just returns [ ]
    send: b’GET /apis/dashboard.grafana.app/v1beta1/namespaces/org-196/dashboards HTTP/1.1\r\nHost: redacted\r\nUser-Agent: python-requests/2.29.0\r\nAccept-Encoding: gzip, deflate, br\r\nAccept: /\r\nConnection: keep-alive\r\nAuthorization: Bearer redacted\r\n\r\n’
    reply: ‘HTTP/1.1 200 OK\r\n’

  • What happened?
    400 Bad Request

  • What did you expect to happen?
    The permissions would be applied to the dashboard

  • Can you copy/paste the configuration(s) that you are having problems with?
    The post requests were provided above

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No errors that I observed

  • Did you follow any online instructions? If so, what is the URL?
    Dashboard HTTP API | Grafana documentation
    Dashboard Permissions HTTP API | Grafana documentation

    Thank you!

I have also tried the following POST as well via the RBAC API based on what the web UI uses but it fails as well though the GET works.

send: b’POST /api/access-control/dashboards/redacted/builtInRoles/Viewer HTTP/1.1\r\nHost: redacted\r\nUser-Agent: python-requests/2.29.0\r\nAccept-Encoding: gzip, deflate, br\r\nAccept: /\r\nConnection: keep-alive\r\nAuthorization: Bearer redacted\r\nx-grafana-org-id: 196\r\nContent-Length: 21\r\n\r\n’
send: b’{“permission”:“View”}’
reply: ‘HTTP/1.1 400 Bad Request\r\n’

send: b’GET /api/access-control/dashboards/redacted HTTP/1.1\r\nHost: redacted\r\nUser-Agent: python-requests/2.29.0\r\nAccept-Encoding: gzip, deflate, br\r\nAccept: /\r\nConnection: keep-alive\r\nAuthorization: Bearer redacted\r\nx-grafana-org-id: 196\r\n\r\n’
reply: ‘HTTP/1.1 200 OK\r\n’
[{‘id’: 0, ‘roleName’: ‘’, ‘isManaged’: False, ‘isInherited’: False, ‘isServiceAccount’: False, ‘builtInRole’: ‘Admin’, ‘actions’: [‘annotations:write’, ‘annotations:delete’, ‘annotations:create’, ‘dashboards.permissions:read’, ‘dashboards:write’, ‘dashboards:delete’, ‘dashboards.permissions:write’, ‘dashboards:read’, ‘annotations:read’], ‘permission’: ‘Admin’}]

It’s solved by adding content-type application/json header

send: b’POST /api/dashboards/uid/redacted/permissions HTTP/1.1\r\nHost: redacted\r\nUser-Agent: python-requests/2.29.0\r\nAccept-Encoding: gzip, deflate, br\r\nAccept: /\r\nConnection: keep-alive\r\nAuthorization: Bearer redacted\r\nContent-Type: application/json\r\nx-grafana-org-id: 196\r\nContent-Length: 48\r\n\r\n’
send: b’{“items”: [{“role”: “Viewer”, “permission”: 1}]}’
reply: ‘HTTP/1.1 200 OK\r\n’

1 Like