mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
- also add Get by UID+OrgID to datasource cache - Refactor backend commands for Delete and Get to be unified
500 lines
9.8 KiB
Markdown
500 lines
9.8 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.
|