Annotations resources / actions

This is the API documentation for the new Grafana Annotations feature released in Grafana 4.6. Annotations are saved in the Grafana database (sqlite, mysql or postgres). Annotations can be global annotations that can be shown on any dashboard by configuring an annotation data source - they are filtered by tags. Or they can be tied to a panel on a dashboard and are then only shown on that panel.

Find Annotations

GET /api/annotations?from=1506676478816&to=1507281278816&tags=tag1&tags=tag2&limit=100

Example Request:

  1. GET /api/annotations?from=1506676478816&to=1507281278816&tags=tag1&tags=tag2&limit=100 HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. Authorization: Basic YWRtaW46YWRtaW4=

Query Parameters:

  • from: epoch datetime in milliseconds. Optional.
  • to: epoch datetime in milliseconds. Optional.
  • limit: number. Optional - default is 100. Max limit for results returned.
  • alertId: number. Optional. Find annotations for a specified alert.
  • dashboardId: number. Optional. Find annotations that are scoped to a specific dashboard
  • panelId: number. Optional. Find annotations that are scoped to a specific panel
  • userId: number. Optional. Find annotations created by a specific user
  • type: string. Optional. alert|annotation Return alerts or user created annotations
  • tags: string. Optional. Use this to filter global annotations. Global annotations are annotations from an annotation data source that are not connected specifically to a dashboard or panel. To do an “AND” filtering with multiple tags, specify the tags parameter multiple times e.g. tags=tag1&tags=tag2.Example Response:
  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. [
  4. {
  5. "id": 1124,
  6. "alertId": 0,
  7. "dashboardId": 468,
  8. "panelId": 2,
  9. "userId": 1,
  10. "userName": "",
  11. "newState": "",
  12. "prevState": "",
  13. "time": 1507266395000,
  14. "text": "test",
  15. "metric": "",
  16. "regionId": 1123,
  17. "type": "event",
  18. "tags": [
  19. "tag1",
  20. "tag2"
  21. ],
  22. "data": {}
  23. },
  24. {
  25. "id": 1123,
  26. "alertId": 0,
  27. "dashboardId": 468,
  28. "panelId": 2,
  29. "userId": 1,
  30. "userName": "",
  31. "newState": "",
  32. "prevState": "",
  33. "time": 1507265111000,
  34. "text": "test",
  35. "metric": "",
  36. "regionId": 1123,
  37. "type": "event",
  38. "tags": [
  39. "tag1",
  40. "tag2"
  41. ],
  42. "data": {}
  43. }
  44. ]

Create Annotation

Creates an annotation in the Grafana database. The dashboardId and panelId fields are optional. If they are not specified then a global annotation is created and can be queried in any dashboard that adds the Grafana annotations data source. When creating a region annotation the response will include both id and endId, if not only id.

POST /api/annotations

Example Request:

  1. POST /api/annotations HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. {
  5. "dashboardId":468,
  6. "panelId":1,
  7. "time":1507037197339,
  8. "isRegion":true,
  9. "timeEnd":1507180805056,
  10. "tags":["tag1","tag2"],
  11. "text":"Annotation Description"
  12. }

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "message":"Annotation added",
  5. "id": 1,
  6. "endId": 2
  7. }

Create Annotation in Graphite format

Creates an annotation by using Graphite-compatible event format. The when and data fields are optional. If when is not specified then the current time will be used as annotation’s timestamp. The tags field can also be in prior to Graphite 0.10.0 format (string with multiple tags being separated by a space).

POST /api/annotations/graphite

Example Request:

  1. POST /api/annotations/graphite HTTP/1.1
  2. Accept: application/json
  3. Content-Type: application/json
  4. {
  5. "what": "Event - deploy",
  6. "tags": ["deploy", "production"],
  7. "when": 1467844481,
  8. "data": "deploy of master branch happened at Wed Jul 6 22:34:41 UTC 2016"
  9. }

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "message":"Graphite annotation added",
  5. "id": 1
  6. }

Update Annotation

PUT /api/annotations/:id

Updates all properties of an annotation that matches the specified id. To only update certain property, consider using the Patch Annotation operation.

Example Request:

  1. PUT /api/annotations/1141 HTTP/1.1
  2. Accept: application/json
  3. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
  4. Content-Type: application/json
  5. {
  6. "time":1507037197339,
  7. "isRegion":true,
  8. "timeEnd":1507180805056,
  9. "text":"Annotation Description",
  10. "tags":["tag3","tag4","tag5"]
  11. }

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "message":"Annotation updated"
  5. }

Patch Annotation

This is available in Grafana 6.0.0-beta2 and above.

PATCH /api/annotations/:id

Updates one or more properties of an annotation that matches the specified id.

This operation currently supports updating of the text, tags, time and timeEnd properties. It does not handle updating of the isRegion and regionId properties. To make an annotation regional or vice versa, consider using the Update Annotation operation.

Example Request:

  1. PATCH /api/annotations/1145 HTTP/1.1
  2. Accept: application/json
  3. Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
  4. Content-Type: application/json
  5. {
  6. "text":"New Annotation Description",
  7. "tags":["tag6","tag7","tag8"]
  8. }

Example Response:

  1. HTTP/1.1 200
  2. Content-Type: application/json
  3. {
  4. "message":"Annotation patched"
  5. }

Delete Annotation By Id

DELETE /api/annotations/:id

Deletes the annotation that matches the specified id.

Example Request:

  1. DELETE /api/annotations/1 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":"Annotation deleted"
  5. }

Delete Annotation By RegionId

DELETE /api/annotations/region/:id

Deletes the annotation that matches the specified region id. A region is an annotation that covers a timerange and has a start and end time. In the Grafana database, this is a stored as two annotations connected by a region id.

Example Request:

  1. DELETE /api/annotations/region/1 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":"Annotation region deleted"
  5. }