grafana/docs/sources/http_api/org.md

477 lines
8.4 KiB
Markdown
Raw Normal View History

+++
title = "Organisation HTTP API "
description = "Grafana Organisation HTTP API"
keywords = ["grafana", "http", "documentation", "api", "organisation"]
aliases = ["/http_api/organisation/"]
type = "docs"
[menu.docs]
name = "Organisation"
parent = "http_api"
+++
2016-02-03 00:59:22 -06:00
2016-02-05 03:47:34 -06:00
# Organisation API
2016-02-03 00:59:22 -06:00
The Organisation HTTP API is divided in two resources, `/api/org` (current organisation)
and `/api/orgs` (admin organisations). One big difference between these are that
the admin of all organisations API only works with basic authentication, see [Admin Organisations API](#admin-organisations-api) for more information.
## Current Organisation API
### Get current Organisation
2016-02-03 00:59:22 -06:00
`GET /api/org/`
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
GET /api/org/ HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{
"id":1,
"name":"Main Org."
}
```
2016-02-03 00:59:22 -06:00
### Get all users within the current organisation
2016-02-03 00:59:22 -06:00
`GET /api/org/users`
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
GET /api/org/users HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
[
{
"orgId":1,
"userId":1,
"email":"admin@mygraf.com",
"login":"admin",
"role":"Admin"
}
]
```
2016-02-03 00:59:22 -06:00
### Updates the given user
`PATCH /api/org/users/:userId`
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
PATCH /api/org/users/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"role": "Viewer",
}
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
{"message":"Organization user updated"}
```
2016-02-03 00:59:22 -06:00
### Delete user in current organisation
`DELETE /api/org/users/:userId`
**Example Request**:
```http
DELETE /api/org/users/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
{"message":"User removed from organization"}
```
### Update current Organisation
2016-02-03 00:59:22 -06:00
`PUT /api/org`
**Example Request**:
```http
PUT /api/org HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
2016-02-03 00:59:22 -06:00
{
"name":"Main Org."
}
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{"message":"Organization updated"}
```
2016-02-03 00:59:22 -06:00
### Add a new user to the current organisation
2016-02-03 00:59:22 -06:00
`POST /api/org/users`
Adds a global user to the current organisation.
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
POST /api/org/users HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
{
"role": "Admin",
"loginOrEmail": "admin"
}
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
{"message":"User added to organization"}
```
2016-02-03 00:59:22 -06:00
## Admin Organisations API
2016-02-03 00:59:22 -06:00
The Admin Organisations HTTP API does not currently work with an API Token. API Tokens are currently
only linked to an organization and an organization role. They cannot be given the permission of server
admin, only users can be given that permission. So in order to use these API calls you will have to
use Basic Auth and the Grafana user must have the Grafana Admin permission (The default admin user
is called `admin` and has permission to use this API).
### Get Organisation by Id
`GET /api/orgs/:orgId`
2016-02-03 00:59:22 -06:00
Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api).
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
GET /api/orgs/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{
"id":1,
"name":"Main Org.",
"address":{
"address1":"",
"address2":"",
"city":"",
"zipCode":"",
"state":"",
"country":""
}
}
```
### Get Organisation by Name
2016-02-03 00:59:22 -06:00
`GET /api/orgs/name/:orgName`
2016-02-03 00:59:22 -06:00
Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api).
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
GET /api/orgs/name/Main%20Org%2E HTTP/1.1
Accept: application/json
Content-Type: application/json
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{
"id":1,
"name":"Main Org.",
"address":{
"address1":"",
"address2":"",
"city":"",
"zipCode":"",
"state":"",
"country":""
}
}
```
2016-02-03 00:59:22 -06:00
### Create Organisation
2016-02-03 00:59:22 -06:00
`POST /api/orgs`
Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api).
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
POST /api/orgs HTTP/1.1
Accept: application/json
Content-Type: application/json
{
"name":"New Org."
}
```
Note: The api will work in the following two ways
1) Need to set GF_USERS_ALLOW_ORG_CREATE=true
2) Set the config users.allow_org_create to true in ini file
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{
"orgId":"1",
"message":"Organization created"
}
```
2016-02-03 00:59:22 -06:00
### Search all Organisations
2016-02-03 00:59:22 -06:00
`GET /api/orgs`
Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api).
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
GET /api/orgs HTTP/1.1
Accept: application/json
Content-Type: application/json
```
Note: The api will only work when you pass the admin name and password
to the request http url, like http://admin:admin@localhost:3000/api/orgs
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2016-02-03 00:59:22 -06:00
[
{
"id":1,
"name":"Main Org."
}
]
```
2016-02-03 00:59:22 -06:00
### Update Organisation
2016-02-03 00:59:22 -06:00
`PUT /api/orgs/:orgId`
2018-04-13 13:02:45 -05:00
Update Organisation, fields *Address 1*, *Address 2*, *City* are not implemented yet.
Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api).
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
PUT /api/orgs/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{
"name":"Main Org 2."
}
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{"message":"Organization updated"}
```
2016-02-03 00:59:22 -06:00
### Delete Organisation
`DELETE /api/orgs/:orgId`
Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api).
**Example Request**:
```http
DELETE /api/orgs/1 HTTP/1.1
Accept: application/json
```
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
{"message":"Organization deleted"}
```
### Get Users in Organisation
2016-02-03 00:59:22 -06:00
`GET /api/orgs/:orgId/users`
Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api).
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
GET /api/orgs/1/users HTTP/1.1
Accept: application/json
Content-Type: application/json
```
Note: The api will only work when you pass the admin name and password
to the request http url, like http://admin:admin@localhost:3000/api/orgs/1/users
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
[
{
"orgId":1,
"userId":1,
"email":"admin@mygraf.com",
"login":"admin",
"role":"Admin"
}
]
```
2016-02-03 00:59:22 -06:00
### Add User in Organisation
2016-02-03 00:59:22 -06:00
`POST /api/orgs/:orgId/users`
Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api).
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
POST /api/orgs/1/users HTTP/1.1
Accept: application/json
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{
"loginOrEmail":"user",
"role":"Viewer"
}
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{"message":"User added to organization"}
```
2016-02-03 00:59:22 -06:00
### Update Users in Organisation
2016-02-03 00:59:22 -06:00
`PATCH /api/orgs/:orgId/users/:userId`
Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api).
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
PATCH /api/orgs/1/users/2 HTTP/1.1
Accept: application/json
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{
"role":"Admin"
}
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{"message":"Organization user updated"}
```
2016-02-03 00:59:22 -06:00
### Delete User in Organisation
2016-02-03 00:59:22 -06:00
`DELETE /api/orgs/:orgId/users/:userId`
Only works with Basic Authentication (username and password), see [introduction](#admin-organisations-api).
2016-02-03 00:59:22 -06:00
**Example Request**:
```http
DELETE /api/orgs/1/users/2 HTTP/1.1
Accept: application/json
Content-Type: application/json
```
2016-02-03 00:59:22 -06:00
**Example Response**:
```http
HTTP/1.1 200
Content-Type: application/json
2016-02-03 00:59:22 -06:00
{"message":"User removed from organization"}
2018-04-13 13:02:45 -05:00
```