组织 API - Amazon Managed Grafana

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

组织 API

使用组织 API 与亚马逊托管 Grafana 工作空间中的组织合作。

注意

要在亚马逊托管 Grafana 工作空间中使用 Grafana API,您必须拥有有效的 Grafana API 令牌。您可以将其包含在 API 请求的Authorization字段中。有关如何创建令牌来验证您的 API 调用的信息,请参阅使用令牌进行身份验证

获取当前组织

GET /api/org/

示例请求

GET /api/org/ HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

响应示例

HTTP/1.1 200 Content-Type: application/json { "id":1, "name":"Main Org." }

获取当前组织中的所有用户

GET /api/org/users

所需权限:具有org.users:read作用域的操作 users:*

示例请求

GET /api/org/users HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

响应示例

HTTP/1.1 200 Content-Type: application/json [ { "orgId": 1, "userId": 1, "email": "admin@localhost", "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae", "login": "admin", "role": "Admin", "lastSeenAt": "2019-08-09T11:02:49+02:00", "lastSeenAtAge": "< 1m" } ]

获取当前组织内的所有用户(查找)

GET /api/org/users/lookup

返回当前组织内的所有用户,但其详细信息较少。具有组织管理员角色的用户、任何文件夹的管理员或任何团队的管理员都可以访问。Grafana UI 主要用于在添加团队成员和编辑文件夹/仪表板权限时提供用户列表。

示例请求

GET /api/org/users/lookup HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

响应示例

HTTP/1.1 200 Content-Type: application/json [ { "userId": 1, "login": "admin", "avatarUrl": "/avatar/46d229b033af06a191ff2267bca9ae" } ]

更新给定用户

PATCH /api/org/users/:userId

所需权限:具有org.users.role:update作用域的操作 users:*

示例请求

PATCH /api/org/users/1 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk { "role": "Viewer", }

响应示例

HTTP/1.1 200 Content-Type: application/json {"message":"Organization user updated"}

删除当前组织中的用户

DELETE /api/org/users/:userId

所需权限:具有org.users:remove作用域的操作 users:*

示例请求

DELETE /api/org/users/1 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

响应示例

HTTP/1.1 200 Content-Type: application/json {"message":"User removed from organization"}

更新当前组织

PUT /api/org

示例请求

PUT /api/org HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk { "name":"Main Org." }

响应示例

HTTP/1.1 200 Content-Type: application/json {"message":"Organization updated"}

将用户添加到当前组织

POST /api/org/users

所需权限:具有org.users:add作用域的操作 users:*

示例请求

POST /api/org/users HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk { "role": "Admin", "loginOrEmail": "admin" }

响应示例

HTTP/1.1 200 Content-Type: application/json {"message":"User added to organization","userId":1}