@ -41,7 +41,7 @@ then there are two flags that can be used to set homepath and the config file pa
If you have not lost the admin password then it is better to set in the Grafana UI. If you need to set the password in a script then the [Grafana API](http://docs.grafana.org/http_api/user/#change-password) can be used. Here is an example with curl using basic auth:
```
```bash
curl -X PUT -H "Content-Type: application/json" -d '{
@ -183,26 +187,30 @@ Only works with Basic Authentication (username and password). See [introduction]
**Example Request**:
GET /api/admin/stats
Accept: application/json
Content-Type: application/json
```bash
GET /api/admin/stats
Accept: application/json
Content-Type: application/json
```
**Example Response**:
HTTP/1.1 200
Content-Type: application/json
{
"user_count":2,
"org_count":1,
"dashboard_count":4,
"db_snapshot_count":2,
"db_tag_count":6,
"data_source_count":1,
"playlist_count":1,
"starred_db_count":2,
"grafana_admin_count":2
}
```json
HTTP/1.1 200
Content-Type: application/json
{
"user_count":2,
"org_count":1,
"dashboard_count":4,
"db_snapshot_count":2,
"db_tag_count":6,
"data_source_count":1,
"playlist_count":1,
"starred_db_count":2,
"grafana_admin_count":2
}
```
## Global Users
@ -211,24 +219,28 @@ Only works with Basic Authentication (username and password). See [introduction]
Create new user. Only works with Basic Authentication (username and password). See [introduction](http://docs.grafana.org/http_api/admin/#admin-api) for an explanation.
**Example Request**:
```json
POST /api/admin/users HTTP/1.1
Accept: application/json
Content-Type: application/json
POST /api/admin/users HTTP/1.1
Accept: application/json
Content-Type: application/json
{
"name":"User",
"email":"user@graf.com",
"login":"user",
"password":"userpassword"
}
{
"name":"User",
"email":"user@graf.com",
"login":"user",
"password":"userpassword"
}
```
**Example Response**:
HTTP/1.1 200
Content-Type: application/json
```json
HTTP/1.1 200
Content-Type: application/json
{"id":5,"message":"User created"}
{"id":5,"message":"User created"}
```
## Password for User
@ -239,18 +251,22 @@ Change password for a specific user.
**Example Request**:
PUT /api/admin/users/2/password HTTP/1.1
Accept: application/json
Content-Type: application/json
```json
PUT /api/admin/users/2/password HTTP/1.1
Accept: application/json
Content-Type: application/json
{"password":"userpassword"}
{"password":"userpassword"}
```
**Example Response**:
HTTP/1.1 200
Content-Type: application/json
```json
HTTP/1.1 200
Content-Type: application/json
{"message": "User password updated"}
{"message": "User password updated"}
```
## Permissions
@ -260,18 +276,22 @@ Only works with Basic Authentication (username and password). See [introduction]
**Example Request**:
PUT /api/admin/users/2/permissions HTTP/1.1
Accept: application/json
Content-Type: application/json
```json
PUT /api/admin/users/2/permissions HTTP/1.1
Accept: application/json
Content-Type: application/json
{"isGrafanaAdmin": true}
{"isGrafanaAdmin": true}
```
**Example Response**:
HTTP/1.1 200
Content-Type: application/json
```json
HTTP/1.1 200
Content-Type: application/json
{message: "User permissions updated"}
{message: "User permissions updated"}
```
## Delete global User
@ -281,16 +301,20 @@ Only works with Basic Authentication (username and password). See [introduction]
**Example Request**:
DELETE /api/admin/users/2 HTTP/1.1
Accept: application/json
Content-Type: application/json
```json
DELETE /api/admin/users/2 HTTP/1.1
Accept: application/json
Content-Type: application/json
```
**Example Response**:
HTTP/1.1 200
Content-Type: application/json
```json
HTTP/1.1 200
Content-Type: application/json
{message: "User deleted"}
{message: "User deleted"}
```
## Pause all alerts
@ -300,13 +324,15 @@ Only works with Basic Authentication (username and password). See [introduction]
**Example Request**:
POST /api/admin/pause-all-alerts HTTP/1.1
Accept: application/json
Content-Type: application/json
```json
POST /api/admin/pause-all-alerts HTTP/1.1
Accept: application/json
Content-Type: application/json
{
"paused": true
}
{
"paused": true
}
```
JSON Body schema:
@ -314,7 +340,9 @@ JSON Body schema:
**Example Response**:
HTTP/1.1 200
Content-Type: application/json
```json
HTTP/1.1 200
Content-Type: application/json
{state: "new state", message: "alerts pause/un paused", "alertsAffected": 100}
{state: "new state", message: "alerts pause/un paused", "alertsAffected": 100}
- **dashboard** – Required. The complete dashboard model.
- **name** – Optional. snapshot name
- **expires** - Optional. When the snapshot should expire in seconds. 3600 is 1 hour, 86400 is 1 day. Default is never to expire.
- **expires** - Optional. When the snapshot should expire in seconds. 3600 is 1 hour, 86400 is 1 day. Default is never to expire.
- **external** - Optional. Save the snapshot on an external server rather than locally. Default is `false`.
- **key** - Optional. Define the unique key. Required if **external** is `true`.
- **deleteKey** - Optional. Unique key used to delete the snapshot. It is different from the **key** so that only the creator can delete the snapshot. Required if **external** is `true`.
Default value for the `perpage` parameter is `1000` and for the `page` parameter is `1`. Requires basic authentication and that the authenticated user is a Grafana Admin.
**Example Response**:
HTTP/1.1 200
Content-Type: application/json
[
{
"id": 1,
"name": "Admin",
"login": "admin",
"email": "admin@mygraf.com",
"isAdmin": true
},
{
"id": 2,
"name": "User",
"login": "user",
"email": "user@mygraf.com",
"isAdmin": false
}
]
```http
HTTP/1.1 200
Content-Type: application/json
[
{
"id": 1,
"name": "Admin",
"login": "admin",
"email": "admin@mygraf.com",
"isAdmin": true
},
{
"id": 2,
"name": "User",
"login": "user",
"email": "user@mygraf.com",
"isAdmin": false
}
]
```
## Search Users with Paging
@ -52,10 +56,12 @@ Default value for the `perpage` parameter is `1000` and for the `page` parameter
**Example Request**:
GET /api/users/search?perpage=10&page=1&query=mygraf HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
```http
GET /api/users/search?perpage=10&page=1&query=mygraf HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
```
Default value for the `perpage` parameter is `1000` and for the `page` parameter is `1`. The `totalCount` field in the response can be used for pagination of the user list E.g. if `totalCount` is equal to 100 users and the `perpage` parameter is set to 10 then there are 10 pages of users. The `query` parameter is optional and it will return results where the query value is contained in one of the `name`, `login` or `email` fields. Query values with spaces need to be url encoded e.g. `query=Jane%20Doe`.
@ -63,29 +69,31 @@ Requires basic authentication and that the authenticated user is a Grafana Admin
**Example Response**:
HTTP/1.1 200
Content-Type: application/json
```http
HTTP/1.1 200
Content-Type: application/json
{
"totalCount": 2,
"users": [
{
"totalCount": 2,
"users": [
{
"id": 1,
"name": "Admin",
"login": "admin",
"email": "admin@mygraf.com",
"isAdmin": true
},
{
"id": 2,
"name": "User",
"login": "user",
"email": "user@mygraf.com",
"isAdmin": false
}
],
"page": 1,
"perPage": 10
"id": 1,
"name": "Admin",
"login": "admin",
"email": "admin@mygraf.com",
"isAdmin": true
},
{
"id": 2,
"name": "User",
"login": "user",
"email": "user@mygraf.com",
"isAdmin": false
}
],
"page": 1,
"perPage": 10
}
```
## Get single user by Id
@ -93,26 +101,29 @@ Requires basic authentication and that the authenticated user is a Grafana Admin
**Example Request**:
GET /api/users/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
```http
GET /api/users/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Basic YWRtaW46YWRtaW4=
```
Requires basic authentication and that the authenticated user is a Grafana Admin.
**Example Response**:
HTTP/1.1 200
Content-Type: application/json
```http
HTTP/1.1 200
Content-Type: application/json
{
"email": "user@mygraf.com"
"name": "admin",
"login": "admin",
"theme": "light",
"orgId": 1,
"isGrafanaAdmin": true
}
{
"email": "user@mygraf.com"
"name": "admin",
"login": "admin",
"theme": "light",
"orgId": 1,
"isGrafanaAdmin": true
}
```
## Get single user by Username(login) or Email
@ -120,34 +131,39 @@ Requires basic authentication and that the authenticated user is a Grafana Admin
**Example Request using the email as option**:
GET /api/users/lookup?loginOrEmail=user@mygraf.com HTTP/1.1
2. Use the Grafana API to find the plugin using this url `https://grafana.com/api/plugins/<plugin id from step 1>`. For example: https://grafana.com/api/plugins/jdbranham-diagram-panel should return:
```
```bash
{
"id": 145,
"typeId": 3,
@ -97,7 +97,7 @@ To manually install a Plugin via the Grafana.com API:
@ -20,20 +20,20 @@ dev environment. Grafana ships with its own required backend server; also comple
## Get Code
Create a directory for the project and set your path accordingly (or use the [default Go workspace directory](https://golang.org/doc/code.html#GOPATH)). Then download and install Grafana into your $GOPATH directory:
```
```bash
export GOPATH=`pwd`
go get github.com/grafana/grafana
```
On Windows use setx instead of export and then restart your command prompt:
```
```bash
setx GOPATH %cd%
```
You may see an error such as: `package github.com/grafana/grafana: no buildable Go source files`. This is just a warning, and you can proceed with the directions.
## Building the backend
```
```bash
cd $GOPATH/src/github.com/grafana/grafana
go run build.go setup
go run build.go build # (or 'go build ./pkg/cmd/grafana-server')
@ -45,7 +45,7 @@ to install GCC. We recommend [TDM-GCC](http://tdm-gcc.tdragon.net/download).
[node-gyp](https://github.com/nodejs/node-gyp#installation) is the Node.js native addon build tool and it requires extra dependencies to be installed on Windows. In a command prompt which is run as administrator, run:
@ -24,7 +24,7 @@ When a user creates a new dashboard, a new dashboard JSON object is initialized
> Note: In the following JSON, id is shown as null which is the default value assigned to it until a dashboard is saved. Once a dashboard is saved, an integer value is assigned to the `id` field.
@ -22,24 +22,24 @@ Some parts of the API are only available through basic authentication and these
The task is to create a new organization and then add a Token that can be used by other users. In the examples below which use basic auth, the user is `admin` and the password is `admin`.
1. [Create the org](http://docs.grafana.org/http_api/org/#create-organisation). Here is an example using curl:
```
```bash
curl -X POST -H "Content-Type: application/json" -d '{"name":"apiorg"}' http://admin:admin@localhost:3000/api/orgs
```
This should return a response: `{"message":"Organization created","orgId":6}`. Use the orgId for the next steps.
2. Optional step. If the org was created previously and/or step 3 fails then first [add your Admin user to the org](http://docs.grafana.org/http_api/org/#add-user-in-organisation):