mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 20:54:22 -06:00
79fea5df2a
* Update guide on authenticating data source plugins * Fix broken references
430 lines
8.5 KiB
Markdown
430 lines
8.5 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/"]
|
|
type = "docs"
|
|
[menu.docs]
|
|
name = "Data source"
|
|
parent = "http_api"
|
|
+++
|
|
|
|
|
|
# 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 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 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.
|