

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 偏好設定 API
<a name="Grafana-API-Preferences"></a>

使用偏好設定 API 來處理 Amazon Managed Grafana 工作區中的使用者偏好設定。

金鑰：
+ **佈景主題** - 有效值為 `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"}
```