2017-10-07 03:31:39 -05:00
+++
title = "Annotations HTTP API "
description = "Grafana Annotations HTTP API"
keywords = ["grafana", "http", "documentation", "api", "annotation", "annotations", "comment"]
2019-12-30 01:17:03 -06:00
aliases = ["/docs/grafana/latest/http_api/annotations/"]
2017-10-07 03:31:39 -05:00
type = "docs"
[menu.docs]
name = "Annotations"
identifier = "annotationshttp"
parent = "http_api"
+++
# 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**:
```http
GET /api/annotations?from=1506676478816& to=1507281278816& tags=tag1& tags=tag2& limit=100 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
```
Query Parameters:
- `from` : epoch datetime in milliseconds. Optional.
- `to` : epoch datetime in milliseconds. Optional.
2018-04-13 03:58:29 -05:00
- `limit` : number. Optional - default is 100. Max limit for results returned.
2017-10-07 03:31:39 -05:00
- `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
2018-03-22 09:52:09 -05:00
- `userId` : number. Optional. Find annotations created by a specific user
- `type` : string. Optional. `alert` |`annotation` Return alerts or user created annotations
2017-10-07 03:31:39 -05:00
- `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**:
```http
HTTP/1.1 200
Content-Type: application/json
[
{
"id": 1124,
"alertId": 0,
"dashboardId": 468,
"panelId": 2,
"userId": 1,
"userName": "",
"newState": "",
"prevState": "",
"time": 1507266395000,
2019-08-16 03:49:30 -05:00
"timeEnd": 1507266395000,
2017-10-07 03:31:39 -05:00
"text": "test",
"metric": "",
"type": "event",
"tags": [
"tag1",
"tag2"
],
"data": {}
},
{
"id": 1123,
"alertId": 0,
"dashboardId": 468,
"panelId": 2,
"userId": 1,
"userName": "",
"newState": "",
"prevState": "",
"time": 1507265111000,
"text": "test",
"metric": "",
"type": "event",
"tags": [
"tag1",
"tag2"
],
"data": {}
}
]
```
2019-08-16 04:45:30 -05:00
> Starting in Grafana v6.4 regions annotations are now returned in one entity that now includes the timeEnd property.
2017-10-07 03:31:39 -05:00
## Create Annotation
2019-08-16 04:45:30 -05:00
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 include the timeEnd property.
2017-10-07 03:31:39 -05:00
`POST /api/annotations`
**Example Request**:
2019-02-06 07:26:43 -06:00
```http
2017-10-07 03:31:39 -05:00
POST /api/annotations HTTP/1.1
Accept: application/json
Content-Type: application/json
{
"dashboardId":468,
"panelId":1,
"time":1507037197339,
"timeEnd":1507180805056,
"tags":["tag1","tag2"],
"text":"Annotation Description"
}
```
**Example Response**:
2019-02-06 07:26:43 -06:00
```http
2017-10-07 03:31:39 -05:00
HTTP/1.1 200
Content-Type: application/json
2017-11-16 07:24:56 -06:00
{
"message":"Annotation added",
"id": 1,
}
2017-10-07 03:31:39 -05:00
```
2019-08-16 04:45:30 -05:00
> The response for this HTTP request is slightly different in versions prior to v6.4. In prior versions you would
2019-10-03 11:20:52 -05:00
also get an endId if you where creating a region. But in 6.4 regions are represented using a single event with time and
2019-08-16 04:45:30 -05:00
timeEnd properties.
2017-10-18 03:13:02 -05:00
## 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**:
2019-02-06 07:26:43 -06:00
```http
2017-10-18 03:13:02 -05:00
POST /api/annotations/graphite HTTP/1.1
Accept: application/json
Content-Type: application/json
{
"what": "Event - deploy",
"tags": ["deploy", "production"],
"when": 1467844481,
"data": "deploy of master branch happened at Wed Jul 6 22:34:41 UTC 2016"
}
```
**Example Response**:
2019-02-06 07:26:43 -06:00
```http
2017-10-18 03:13:02 -05:00
HTTP/1.1 200
Content-Type: application/json
2017-11-16 07:24:56 -06:00
{
"message":"Graphite annotation added",
"id": 1
}
2017-10-18 03:13:02 -05:00
```
2019-02-06 07:26:43 -06:00
## Update Annotation
2017-10-07 03:31:39 -05:00
`PUT /api/annotations/:id`
2019-02-06 07:26:43 -06:00
Updates all properties of an annotation that matches the specified id. To only update certain property, consider using the [Patch Annotation ](#patch-annotation ) operation.
2019-01-27 05:49:22 -06:00
2017-10-07 03:31:39 -05:00
**Example Request**:
2019-02-06 07:26:43 -06:00
```http
2017-10-07 03:31:39 -05:00
PUT /api/annotations/1141 HTTP/1.1
Accept: application/json
2019-01-27 05:49:22 -06:00
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
2017-10-07 03:31:39 -05:00
Content-Type: application/json
{
"time":1507037197339,
"timeEnd":1507180805056,
"text":"Annotation Description",
"tags":["tag3","tag4","tag5"]
}
```
2019-02-06 07:26:43 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
{
"message":"Annotation updated"
}
```
## Patch Annotation
2019-06-12 04:14:30 -05:00
> This is available in Grafana 6.0.0-beta2 and above.
2019-01-27 05:49:22 -06:00
`PATCH /api/annotations/:id`
Updates one or more properties of an annotation that matches the specified id.
2019-08-16 04:45:30 -05:00
This operation currently supports updating of the `text` , `tags` , `time` and `timeEnd` properties.
2019-02-05 14:41:39 -06:00
2019-01-27 05:49:22 -06:00
**Example Request**:
2019-02-06 07:26:43 -06:00
```http
2019-01-27 05:49:22 -06:00
PATCH /api/annotations/1145 HTTP/1.1
Accept: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Content-Type: application/json
{
"text":"New Annotation Description",
"tags":["tag6","tag7","tag8"]
}
```
2019-02-06 07:26:43 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
{
"message":"Annotation patched"
}
```
2017-10-07 03:31:39 -05:00
## Delete Annotation By Id
2018-04-09 14:09:37 -05:00
`DELETE /api/annotations/:id`
2017-10-07 03:31:39 -05:00
Deletes the annotation that matches the specified id.
**Example Request**:
```http
2018-04-09 14:09:37 -05:00
DELETE /api/annotations/1 HTTP/1.1
2017-10-07 03:31:39 -05:00
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2019-02-06 07:26:43 -06:00
{
"message":"Annotation deleted"
}
2019-08-16 04:45:30 -05:00
```