Library Element API

Identifier (id) vs unique identifier (uid)

The identifier (ID) of a library element is an auto-incrementing numeric value that is unique per Grafana install.

The unique identifier (UID) of a library element uniquely identifies library elements between multiple Grafana installs. It’s automatically generated unless you specify it during library element creation. The UID provides consistent URLs for accessing library elements and when syncing library elements between multiple Grafana installs.

The maximum length of a UID is 40 characters.

Get all library elements

GET /api/library-elements

Returns a list of all library elements the authenticated user has permission to view. Use the perPage query parameter to control the maximum number of library elements returned; the default limit is 100. You can also use the page query parameter to fetch library elements from any page other than the first one.

Query parameters:

  • searchString – Part of the name or description searched for.
  • kind – Kind of element to search for. Use 1 for library panels or 2 for library variables.
  • sortDirection – Sort order of elements. Use alpha-asc for ascending and alpha-desc for descending sort order.
  • typeFilter – A comma separated list of types to filter the elements by.
  • excludeUid – Element UID to exclude from search results.
  • folderFilter – A comma separated list of folder ID(s) to filter the elements by.
  • perPage – The number of results per page; default is 100.
  • page – The page for a set of records, given that only perPage records are returned at a time. Numbering starts at 1.

Example Request:

  1. GET /api/library-elements?perPage=10 HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "result": {
  5. "totalCount": 15,
  6. "page": 1,
  7. "perPage": 10
  8. "elements": [
  9. {
  10. "id": 25,
  11. "orgId": 1,
  12. "folderId": 0,
  13. "uid": "V--OrYHnz",
  14. "name": "API docs Example",
  15. "kind": 1,
  16. "type": "text",
  17. "description": "",
  18. "model": {...},
  19. "version": 1,
  20. "meta": {
  21. "folderName": "General",
  22. "folderUid": "",
  23. "connectedDashboards": 1,
  24. "created": "2021-09-27T09:56:17+02:00",
  25. "updated": "2021-09-27T09:56:17+02:00",
  26. "createdBy": {
  27. "id": 1,
  28. "name": "admin",
  29. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  30. },
  31. "updatedBy": {
  32. "id": 1,
  33. "name": "admin",
  34. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  35. }
  36. }
  37. },
  38. {...}
  39. {...}
  40. ],
  41. }
  42. }

Status Codes:

  • 200 – Found
  • 401 – Unauthorized

Get library element by uid

GET /api/library-elements/:uid

Returns a library element with the given UID.

Example Request:

  1. GET /api/library-elements/V--OrYHnz HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "result": {
  5. "id": 25,
  6. "orgId": 1,
  7. "folderId": 0,
  8. "uid": "V--OrYHnz",
  9. "name": "API docs Example",
  10. "kind": 1,
  11. "type": "text",
  12. "description": "",
  13. "model": {...},
  14. "version": 1,
  15. "meta": {
  16. "folderName": "General",
  17. "folderUid": "",
  18. "connectedDashboards": 1,
  19. "created": "2021-09-27T09:56:17+02:00",
  20. "updated": "2021-09-27T09:56:17+02:00",
  21. "createdBy": {
  22. "id": 1,
  23. "name": "admin",
  24. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  25. },
  26. "updatedBy": {
  27. "id": 1,
  28. "name": "admin",
  29. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  30. }
  31. }
  32. }
  33. }

Status Codes:

  • 200 – Found
  • 401 – Unauthorized
  • 404 – Library element not found

Get library element by name

GET /api/library-elements/name/:name

Returns a library element with the given name

Example Request:

  1. GET /api/library-elements/name/API docs Example HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "result": [
  5. {
  6. "id": 25,
  7. "orgId": 1,
  8. "folderId": 0,
  9. "uid": "V--OrYHnz",
  10. "name": "API docs Example",
  11. "kind": 1,
  12. "type": "text",
  13. "description": "",
  14. "model": {...},
  15. "version": 1,
  16. "meta": {
  17. "folderName": "General",
  18. "folderUid": "",
  19. "connectedDashboards": 1,
  20. "created": "2021-09-27T09:56:17+02:00",
  21. "updated": "2021-09-27T09:56:17+02:00",
  22. "createdBy": {
  23. "id": 1,
  24. "name": "admin",
  25. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  26. },
  27. "updatedBy": {
  28. "id": 1,
  29. "name": "admin",
  30. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  31. }
  32. }
  33. }
  34. ]
  35. }

Status Codes:

  • 200 – Found
  • 401 – Unauthorized
  • 404 – Library element not found

Get library element connections

GET /api/library-elements/:uid/connections

Returns a list of connections for a library element based on the UID specified.

Example Request:

  1. GET /api/library-elements/V--OrYHnz/connections HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "result": [
  5. {
  6. "id": 148,
  7. "kind": 1,
  8. "elementId": 25,
  9. "connectionId": 527,
  10. "connectionUid": "dHEquNzGz",
  11. "created": "2021-09-27T10:00:07+02:00",
  12. "createdBy": {
  13. "id": 1,
  14. "name": "admin",
  15. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  16. }
  17. }
  18. ]
  19. }

Status Codes:

  • 200 – Found
  • 401 – Unauthorized
  • 404 – Library element not found

Create library element

POST /api/library-elements

Creates a new library element.

JSON Body schema:

  • folderId – ID of the folder where the library element is stored. It is deprecated since Grafana v9
  • folderUid – Optional, the UID of the folder where the library element is stored, empty string when it is General folder
  • name – Optional, the name of the library element.
  • model – The JSON model for the library element.
  • kind – Kind of element to create, Use 1 for library panels or 2 for library variables.
  • uid – Optional, the unique identifier.

Example Request:

  1. POST /api/library-elements HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
  5. {
  6. "uid": "nErXDvCkzz",
  7. "folderUid": "",
  8. "name": "Example library panel",
  9. "model": {...},
  10. "kind": 1
  11. }

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "result": {
  5. "id": 28,
  6. "orgId": 1,
  7. "folderId": 0,
  8. "folderUid": "",
  9. "uid": "nErXDvCkzz",
  10. "name": "Example library panel",
  11. "kind": 1,
  12. "type": "",
  13. "description": "",
  14. "model": {...},
  15. "version": 1,
  16. "meta": {
  17. "folderName": "General",
  18. "folderUid": "",
  19. "connectedDashboards": 0,
  20. "created": "2021-09-30T09:14:22.378307+02:00",
  21. "updated": "2021-09-30T09:14:22.378307+02:00",
  22. "createdBy": {
  23. "id": 1,
  24. "name": "admin",
  25. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  26. },
  27. "updatedBy": {
  28. "id": 1,
  29. "name": "admin",
  30. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  31. }
  32. }
  33. }
  34. }

Status Codes:

  • 200 – Created
  • 400 – Errors (for example, name or UID already exists, invalid JSON, missing or invalid fields, and so on).
  • 401 – Unauthorized
  • 403 – Access denied

Update library element

PATCH /api/library-elements/:uid

Updates an existing library element identified by uid.

JSON Body schema:

  • folderId – ID of the folder where the library element is stored. It is deprecated since Grafana v9
  • folderUid – UID of the folder where the library element is stored, empty string when it is General folder.
  • name – Name of the library element.
  • model – The JSON model for the library element.
  • kind – Kind of element to create. Use 1 for library panels or 2 for library variables.
  • version – Version of the library element you are updating.
  • uid – Optional, the unique identifier.

Example Request:

  1. PATCH /api/library-elements/nErXDvCkzz HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
  5. {
  6. "name": "Renamed library panel",
  7. "kind": 1,
  8. "version": 1
  9. }

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "result": {
  5. "id": 28,
  6. "orgId": 1,
  7. "folderId": 0,
  8. "folderUid": "",
  9. "uid": "nErXDvCkzz",
  10. "name": "Renamed library panel",
  11. "kind": 1,
  12. "type": "",
  13. "description": "",
  14. "model": {
  15. "description": "",
  16. "type": ""
  17. },
  18. "version": 2,
  19. "meta": {
  20. "folderName": "General",
  21. "folderUid": "",
  22. "connectedDashboards": 0,
  23. "created": "2021-09-30T09:14:22+02:00",
  24. "updated": "2021-09-30T09:25:57.697214+02:00",
  25. "createdBy": {
  26. "id": 1,
  27. "name": "admin",
  28. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  29. },
  30. "updatedBy": {
  31. "id": 1,
  32. "name": "admin",
  33. "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae56"
  34. }
  35. }
  36. }
  37. }

Status Codes:

  • 200 – Updated
  • 400 – Errors (for example, name or UID already exists, invalid JSON, missing or invalid fields, and so on).
  • 401 – Unauthorized
  • 403 – Access denied
  • 404 – Library element not found
  • 412 – Version mismatch

Delete library element

DELETE /api/library-elements/:uid

Deletes an existing library element as specified by the UID. This operation cannot be reverted.

Note: You cannot delete a library element that is connected. This operation cannot be reverted.

Example Request:

  1. DELETE /api/library-elements/nErXDvCkzz HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "message": "Library element deleted",
  5. "id": 28
  6. }

Status Codes:

  • 200 – Deleted
  • 401 – Unauthorized
  • 400 – Bad request
  • 403 – Access denied
  • 404 – Library element not found