Datasource Permissions API

Datasource Permissions is only available in Grafana Enterprise. Read more about Grafana Enterprise.

This API can be used to enable, disable, list, add and remove permissions for a datasource.

Permissions can be set for a user or a team. Permissions cannot be set for Admins - they always have access to everything.

The permission levels for the permission field:

  • 1 = Query

Enable permissions for a datasource

POST /api/datasources/:id/enable-permissions

Enables permissions for the datasource with the given id. No one except Org Admins will be able to query the datasource until permissions have been added which permit certain users or teams to query the datasource.

Example request:

  1. POST /api/datasources/1/enable-permissions
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
  5. {}

Example response:

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. Content-Length: 35
  4. {"message":"Datasource permissions enabled"}

Status Codes:

  • 200 - Ok
  • 400 - Permissions cannot be enabled, see response body for details
  • 401 - Unauthorized
  • 403 - Access denied
  • 404 - Datasource not found

Disable permissions for a datasource

POST /api/datasources/:id/disable-permissions

Disables permissions for the datasource with the given id. All existing permissions will be removed and anyone will be able to query the datasource.

Example request:

  1. POST /api/datasources/1/disable-permissions
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
  5. {}

Example response:

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. Content-Length: 35
  4. {"message":"Datasource permissions disabled"}

Status Codes:

  • 200 - Ok
  • 400 - Permissions cannot be disabled, see response body for details
  • 401 - Unauthorized
  • 403 - Access denied
  • 404 - Datasource not found

Get permissions for a datasource

GET /api/datasources/:id/permissions

Gets all existing permissions for the datasource with the given id.

Example request:

  1. GET /api/datasources/1/permissions HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Example Response

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. Content-Length: 551
  4. {
  5. "datasourceId": 1,
  6. "enabled": true,
  7. "permissions":
  8. [
  9. {
  10. "id": 1,
  11. "datasourceId": 1,
  12. "userId": 1,
  13. "userLogin": "user",
  14. "userEmail": "user@test.com",
  15. "userAvatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56",
  16. "permission": 1,
  17. "permissionName": "Query",
  18. "created": "2017-06-20T02:00:00+02:00",
  19. "updated": "2017-06-20T02:00:00+02:00",
  20. },
  21. {
  22. "id": 2,
  23. "datasourceId": 1,
  24. "teamId": 1,
  25. "team": "A Team",
  26. "teamAvatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56",
  27. "permission": 1,
  28. "permissionName": "Query",
  29. "created": "2017-06-20T02:00:00+02:00",
  30. "updated": "2017-06-20T02:00:00+02:00",
  31. }
  32. ]
  33. }

Status Codes:

  • 200 - Ok
  • 401 - Unauthorized
  • 403 - Access denied
  • 404 - Datasource not found

Add permission for a datasource

POST /api/datasources/:id/permissions

Adds a user permission for the datasource with the given id.

Example request:

  1. POST /api/datasources/1/permissions
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
  5. {
  6. "userId": 1,
  7. "permission": 1
  8. }

Example response:

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. Content-Length: 35
  4. {"message":"Datasource permission added"}

Adds a team permission for the datasource with the given id.

Example request:

  1. POST /api/datasources/1/permissions
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
  5. {
  6. "teamId": 1,
  7. "permission": 1
  8. }

Example response:

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. Content-Length: 35
  4. {"message":"Datasource permission added"}

Status Codes:

  • 200 - Ok
  • 400 - Permission cannot be added, see response body for details
  • 401 - Unauthorized
  • 403 - Access denied
  • 404 - Datasource not found

Remove permission for a datasource

DELETE /api/datasources/:id/permissions/:permissionId

Removes the permission with the given permissionId for the datasource with the given id.

Example request:

  1. DELETE /api/datasources/1/permissions/2
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Example response:

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json; charset=UTF-8
  3. Content-Length: 35
  4. {"message":"Datasource permission removed"}

Status Codes:

  • 200 - Ok
  • 401 - Unauthorized
  • 403 - Access denied
  • 404 - Datasource not found or permission not found