# 用戶標籤

## 建立新標籤

在您的伺服器呼叫 BotBonnie 建立標籤的 API：

```
POST https://api.botbonnie.com/v1/api/tag/autogen
```

#### **Request headers**

| Name              | Description          |
| ----------------- | -------------------- |
| **Content-Type**  | application/json     |
| **Authorization** | Bearer `{API Token}` |

* [如何取得 `API Token`](/chang-jian-wen-ti/ru-he-qu-de-api-token.md) ？

#### **Request body**

| Name         | Type   | Description                                                      | Required |
| ------------ | ------ | ---------------------------------------------------------------- | -------- |
| **botId**    | String | 機器人 ID                                                           | o        |
| **name**     | String | 標籤名稱                                                             | o        |
| **type**     | Number | <p>標籤類型</p><p><code>0</code>：用戶標籤</p><p><code>1</code>：標籤資料夾</p> | o        |
| **parentId** | Number | 標籤資料夾 ID                                                         |          |

### API 回覆

#### 新增成功

```
{
    "res": "{
        "id": "tag-xxxxxx" //建立成功之標籤 ID
    }",
    "status": 200
}
```

#### 錯誤

```
{
    "errorMessage": "...",
    "errorCode": 500
}
```

## 取得標籤內容

在您的伺服器呼叫 BotBonnie 取得標籤的 API：

```
GET https://api.botbonnie.com/v1/api/tag/{{tagID}}
```

#### **Query path parameters**

| Name      | Description      |
| --------- | ---------------- |
| **tagId** | 欲查詢的標籤或是標籤資料夾 ID |

#### **Request headers**

| Name              | Description          |
| ----------------- | -------------------- |
| **Content-Type**  | application/json     |
| **Authorization** | Bearer `{API Token}` |

### API 回覆

#### 回應範例

```
{
    "res": {
        "created": 1583983892294, // 標籤建立時的 UNIX 時間戳記（毫秒）
        "id": "tag--PTfLM4wQ", // 標籤 ID
        "name": "測試API標籤 child", // 標籤名稱
        "botId": "bot-WDCLEHlTw", // 機器人 ID
        "type": 0 // 標籤類型
    },
    "status": 200
}
```

## 刪除標籤

在您的伺服器呼叫 BotBonnie 刪除標籤的 API，刪除標籤時，也會同時拔除所有用戶身上的該標籤紀錄。當刪除的標籤為資料夾，會將其資料夾下的標籤與子資料夾一併刪除。<br>

```
DELETE https://api.botbonnie.com/v1/api/tag/{{tagID}}
```

#### **Query path parameters**

| Name      | Description      |
| --------- | ---------------- |
| **tagId** | 欲刪除的標籤或是標籤資料夾 ID |

#### **Request headers**

| Name              | Description          |
| ----------------- | -------------------- |
| **Content-Type**  | application/json     |
| **Authorization** | Bearer `{API Token}` |

### API 回覆

#### 回應範例

```
{
    "res": [
        "tag--PTfLM4Q"
    ], // 此陣列中包含所有被刪除的標籤 ID 與標籤資料夾 ID
    "status": 200
}
```

## 貼標籤到用戶身上

在您的伺服器呼叫 BotBonnie 用戶標籤 API：

```
POST https://api.botbonnie.com/v1/api/user/tag
```

#### **Request headers**

| Name              | Description          |
| ----------------- | -------------------- |
| **Content-Type**  | application/json     |
| **Authorization** | Bearer `{API Token}` |

#### **Request body**

| Name              | Type   | Description                                                     | Required           |
| ----------------- | ------ | --------------------------------------------------------------- | ------------------ |
| **bot\_tag\_id**  | String | 標籤 ID                                                           | o                  |
| **bot\_uid**      | String | 用戶 ID (加密)                                                      | 與 bot\_raw\_uid 擇一 |
| **bot\_raw\_uid** | String | 用戶 ID (未加密)                                                     | 與 bot\_uid 擇一      |
| **bot\_pid**      | String | 粉絲頁 ID                                                          | o                  |
| **bot\_channel**  | Number | <p>渠道代號  <br><code>0</code>：Facebook<br><code>1</code>：LINE</p> | o                  |

## 移除用戶身上的標籤

在您的伺服器呼叫 BotBonnie 用戶標籤 API：

```
DELETE https://api.botbonnie.com/v1/api/user/tag
```

#### **Request headers**

| Name              | Description          |
| ----------------- | -------------------- |
| **Content-Type**  | application/json     |
| **Authorization** | Bearer `{API Token}` |

#### **Request body**

| Name              | Type   | Description                                                     | Required           |
| ----------------- | ------ | --------------------------------------------------------------- | ------------------ |
| **bot\_tag\_id**  | String | 標籤 ID                                                           | o                  |
| **bot\_uid**      | String | 用戶 ID (加密)                                                      | 與 bot\_raw\_uid 擇一 |
| **bot\_raw\_uid** | String | 用戶 ID (未加密)                                                     | 與 bot\_uid 擇一      |
| **bot\_pid**      | String | 粉絲頁 ID                                                          | o                  |
| **bot\_channel**  | Number | <p>渠道代號  <br><code>0</code>：Facebook<br><code>1</code>：LINE</p> | o                  |

### API 回覆

#### 新增 / 刪除成功

```
{
    "res": "ok",
    "status": 200
}
```

#### 錯誤

```
{
    "errorMessage": "...",
    "errorCode": 500
}
```

## 查詢用戶身上的標籤

在您的伺服器呼叫 BotBonnie 用戶標籤 API：

```
POST https://api.botbonnie.com/v1/api/user/taglist
```

#### **Request headers**

| **Name**          | Description          |
| ----------------- | -------------------- |
| **Content-Type**  | application/json     |
| **Authorization** | Bearer `{API Token}` |

#### Request Body

| Name              | Type   | Description                                                     | Required           |
| ----------------- | ------ | --------------------------------------------------------------- | ------------------ |
| **bot\_uid**      | String | 用戶 ID (加密)                                                      | 與 bot\_raw\_uid 擇一 |
| **bot\_raw\_uid** | String | 用戶 ID (未加密)                                                     | 與 bot\_uid 擇一      |
| **bot\_pid**      | String | 粉絲頁 ID                                                          | o                  |
| **bot\_channel**  | Number | <p>渠道代號  <br><code>0</code>：Facebook<br><code>1</code>：LINE</p> | o                  |

### API 回覆

#### 回應範例

```
{
    "res":[
        {
            "bot_uid":"53f224d55bd378237ad26dd0d79002f7206527ab1e91bd3d84bf05c9c6ac761291",
            "bot_raw_uid":"U21ab30ccce78feb456048adeb80cf00a",
            "bot_pid":"test_audi",
            "bot_channel":1,
            "tags":[
                {
                    "id": "tag-4TbbFavFY",
                    "name": "標籤A",
                    "timestamp": 1540869097545
                },
                {
                    "id": "tag-Aw3IcRKNt",
                    "name": "標籤B",
                    "timestamp": 1540869134405
                },
                {
                    "id": "tag-bcpe7NStr",
                    "name": "標籤C",
                    "timestamp": 1540869152985
                }
            ]
        }
    ]
    ,"status":200
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.botbonnie.com/jiao-xue-fan-li/yong-hu-biao-qian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
