mirror of
https://github.com/grafana/grafana.git
synced 2025-02-09 23:16:16 -06:00
* Format md,mdx files with prettier on lint-staged * Manually run prettier on docs/sources
609 lines
13 KiB
Markdown
609 lines
13 KiB
Markdown
+++
|
||
title = "Data source HTTP API "
|
||
description = "Grafana Data source HTTP API"
|
||
keywords = ["grafana", "http", "documentation", "api", "data source"]
|
||
aliases = ["/docs/grafana/latest/http_api/datasource/"]
|
||
+++
|
||
|
||
# Data source API
|
||
|
||
## Get all data sources
|
||
|
||
`GET /api/datasources`
|
||
|
||
**Example Request**:
|
||
|
||
```http
|
||
GET /api/datasources HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
```
|
||
|
||
**Example Response**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
## Get a single data source by Id
|
||
|
||
`GET /api/datasources/:datasourceId`
|
||
|
||
**Example Request**:
|
||
|
||
```http
|
||
GET /api/datasources/1 HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
```
|
||
|
||
**Example Response**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
## Get a single data source by UID
|
||
|
||
`GET /api/datasources/uid/:uid`
|
||
|
||
**Example request:**
|
||
|
||
```http
|
||
GET /api/datasources/uid/kLtEtcRGk HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
```
|
||
|
||
**Example Response**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
## Get a single data source by Name
|
||
|
||
`GET /api/datasources/name/:name`
|
||
|
||
**Example Request**:
|
||
|
||
```http
|
||
GET /api/datasources/name/test_datasource HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
```
|
||
|
||
**Example Response**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
## Get data source Id by Name
|
||
|
||
`GET /api/datasources/id/:name`
|
||
|
||
**Example Request**:
|
||
|
||
```http
|
||
GET /api/datasources/id/test_datasource HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
```
|
||
|
||
**Example Response**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
## Create a data source
|
||
|
||
`POST /api/datasources`
|
||
|
||
**Example Graphite Request**:
|
||
|
||
```http
|
||
POST /api/datasources HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
||
```
|
||
|
||
**Example Graphite Response**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
> **Note:** By defining `password` and `basicAuthPassword` under `secureJsonData` Grafana encrypts them securely as an encrypted blob in the database. The response then lists the encrypted fields under `secureJsonFields`.
|
||
|
||
**Example Graphite Request with basic auth enabled**:
|
||
|
||
```http
|
||
POST /api/datasources HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
||
```
|
||
|
||
**Example Response with basic auth enabled**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
**Example CloudWatch Request**:
|
||
|
||
```http
|
||
POST /api/datasources HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
||
```
|
||
|
||
## Update an existing data source
|
||
|
||
`PUT /api/datasources/:datasourceId`
|
||
|
||
**Example Request**:
|
||
|
||
```http
|
||
PUT /api/datasources/1 HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
||
```
|
||
|
||
**Example Response**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
> **Note:** Similar to [creating a data source](#create-a-data-source), `password` and `basicAuthPassword` should be defined under `secureJsonData` in order to be stored securely as an encrypted blob in the database. Then, the encrypted fields are listed under `secureJsonFields` section in the response.
|
||
|
||
## Delete an existing data source by id
|
||
|
||
`DELETE /api/datasources/:datasourceId`
|
||
|
||
**Example Request**:
|
||
|
||
```http
|
||
DELETE /api/datasources/1 HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
```
|
||
|
||
**Example Response**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
## Delete an existing data source by UID
|
||
|
||
`DELETE /api/datasources/uid/:uid`
|
||
|
||
**Example request:**
|
||
|
||
```http
|
||
DELETE /api/datasources/uid/kLtEtcRGk HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
```
|
||
|
||
**Example response**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
## Delete an existing data source by name
|
||
|
||
`DELETE /api/datasources/name/:datasourceName`
|
||
|
||
**Example Request**:
|
||
|
||
```http
|
||
DELETE /api/datasources/name/test_datasource HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
```
|
||
|
||
**Example Response**:
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
## Data source proxy calls
|
||
|
||
`GET /api/datasources/proxy/:datasourceId/*`
|
||
|
||
Proxies all calls to the actual data source.
|
||
|
||
## Query a data source by ID
|
||
|
||
Queries a data source having backend implementation.
|
||
|
||
`POST /api/tsdb/query`
|
||
|
||
> **Note:** Most of Grafana's builtin data sources have backend implementation.
|
||
|
||
**Example Request**:
|
||
|
||
```http
|
||
POST /api/tsdb/query HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
> **Note:** The `from`, `to`, and `queries` properties are required.
|
||
|
||
JSON Body schema:
|
||
|
||
- **from/to** – Should be either absolute in epoch timestamps in milliseconds or relative using Grafana time units. For example, `now-1h`.
|
||
- **queries.refId** – Specifies an identifier of the query. Is optional and default to "A".
|
||
- **queries.datasourceId** – Specifies the data source to be queried. Each `query` in the request must have an unique `datasourceId`.
|
||
- **queries.maxDataPoints** - Species maximum amount of data points that dashboard panel can render. Is optional and default to 100.
|
||
- **queries.intervalMs** - Specifies the time interval in milliseconds of time series. Is optional and defaults to 1000.
|
||
|
||
In addition, each data source has its own specific properties that should be added in a request.
|
||
|
||
**Example request for the MySQL data source:**
|
||
|
||
```http
|
||
POST /api/tsdb/query HTTP/1.1
|
||
Accept: application/json
|
||
Content-Type: application/json
|
||
|
||
```
|
||
|
||
**Example MySQL time series query response:**
|
||
|
||
```http
|
||
HTTP/1.1 200
|
||
Content-Type: application/json
|
||
|
||
```
|