

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

# 首选项 API
<a name="Grafana-API-Preferences"></a>

使用首选项 API 在 Amazon Managed Grafana 工作区中处理用户首选项。

键：
+ **theme**：有效值为 `light`、`dark` 或使用默认主题的空字符串。
+ **homeDashboardId**— 最喜欢的仪表板`:id`的数字。默认值是 0。
+ **timezone**：有效值为 `utc`、`browser` 或使用默认值的空字符串。

省略键会导致当前值被系统默认值替换。

**注意**  
要对 Amazon Managed Grafana 工作区使用 Grafana API，您必须拥有有效的 Grafana API 令牌。您可以将其包含在 API 请求的 `Authorization` 字段中。有关如何创建令牌对 API 调用进行身份验证的信息，请参阅 [使用令牌进行身份验证](authenticating-grafana-apis.md)。

## 获取当前用户首选项
<a name="Grafana-API-Preferences-get"></a>

```
GET /api/user/preferences
```

**示例请求**

```
GET /api/user/preferences HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
```

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

{"theme":"","homeDashboardId":0,"timezone":""}
```

## 更新当前用户首选项
<a name="Grafana-API-Preferences-update"></a>

```
PUT /api/user/preferences
```

**示例请求**

```
PUT /api/user/preferences HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

{
  "theme": "",
  "homeDashboardId":0,
  "timezone":"utc"
}
```

**响应示例**

```
HTTP/1.1 200
Content-Type: text/plain; charset=utf-8

{"message":"Preferences updated"}
```

## 获取当前组织首选项
<a name="Grafana-API-Preferences-get-org"></a>

```
GET /api/org/preferences
```

**示例请求**

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

**响应示例**

```
HTTP/1.1 200
Content-Type: application/json

{"theme":"","homeDashboardId":0,"timezone":""}
```

## 更新当前组织首选项
<a name="Grafana-API-Playlist-Preferences-update-org"></a>

```
PUT /api/org/preferences
```

**示例请求**

```
PUT /api/org/preferences HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

{
  "theme": "",
  "homeDashboardId":0,
  "timezone":"utc"
}
```

**响应示例**

```
HTTP/1.1 200
Content-Type: text/plain; charset=utf-8

{"message":"Preferences updated"}
```