# 知識庫

## 最佳實踐

### 更新既有知識庫文章

1. **搜尋定位**
   * 透過 list 加上 search 以標題或關鍵字找到目標文章。
   * 確認僅匹配到單一筆資料，取得 `id` 資訊。
2. **條件式更新**
   * 呼叫 update API（PUT / PATCH），並帶上下一次的版本識別條件。

## 搜尋

```javascript
GET https://{API_DOMAIN}/api/v1/kb
```

```javascript
curl -X GET
    -H "Content-Type: application/json"
    '{"search": "vip"}'
    https://{API_HOST}/api/v1/kb
```

### URL Parameters

| 名稱          | 類型      | 必填 | 說明              | 範例                |
| ----------- | ------- | -- | --------------- | ----------------- |
| `page`      | integer | 否  | 頁碼（從 1 開始）      | `page=2`          |
| `search`    | string  | 否  | 按關鍵字過濾 KB 名稱／內容 | `search=security` |
| `is_public` | integer | 否  | 文章是否公開          | `is_public=1`     |

### Response

| PROPERTY | TYPE             | DESCRIPTION |
| -------- | ---------------- | ----------- |
| **data** | Array of objects | 文章資料陣列      |
| **meta** | Object           | 頁籤資料        |

```json
{
    "data": [
    {
        "id": 5,
        "subject": "LINE 圖文選單",
        "content": "<h2>概述</h2><p>圖文選單位於 LINE 官方帳號的聊天室下方，客戶第一眼就會看到圖文選單，.....",
        "like_count": 1,
        "dislike_count": 0,
        "readed_count": 10,
        "is_public": true,
        "hit_count": 0,
        "creater_id": 3,
        "creater":
        {
            "id": 3,
            "name": "eason d",
            "first_name": "eason",
            "last_name": "d",
            "employee_no": "eason",
            "photo_url": null,
            "identity_no": null,
            "job_title_id": -1,
            "department_id": -1,
            "extension_id": -1,
            "profile_id": 6,
            "group_id": null,
            "created_at": "2022-06-25 08:42:44",
            "updated_at": "2025-06-14 10:56:42"
        },
        "sub_category_id": null,
        "sub_category": null,
        "file_entities_count": 0,
        "file_entities": [],
        "category": null,
        "category_id": -1,
        "kb_tags": [],
        "kb_tag_ids": []
    }],
    "links":
    { ...
    },
    "meta":
    { ...
    }
}
```

## 取得單筆資料

```javascript
GET https://{API_DOMAIN}/api/v1/kb/{kb}
```

```javascript
curl -X GET
    -H "Content-Type: application/json"
    https://{API_HOST}/api/v1/kb/3
```

### URL Parameters

| PARAMETER | REQUIRED | DEFAULT | TYPE   | DESCRIPTION |
| --------- | -------- | ------- | ------ | ----------- |
| **id**    | true     | NULL    | Number | 客戶標籤系統 ID   |

### Response

| PROPERTY | TYPE   | DESCRIPTION |
| -------- | ------ | ----------- |
| **data** | Object | 知識庫文章資料     |

```json
{
    "data":
    {
        "id": 5,
        "subject": "LINE 圖文選單",
        "content": "<h2>概述</h2><p>圖文選單位於 LINE 官方帳號的聊天室下方，客戶第一眼就會看到圖文選單，.....",
        "like_count": 1,
        "dislike_count": 0,
        "readed_count": 10,
        "is_public": true,
        "hit_count": 0,
        "creater_id": 3,
        "creater":
        {
            "id": 3,
            "name": "eason d",
            "first_name": "eason",
            "last_name": "d",
            "employee_no": "eason",
            "photo_url": null,
            "identity_no": null,
            "job_title_id": -1,
            "department_id": -1,
            "extension_id": -1,
            "profile_id": 6,
            "group_id": null,
            "created_at": "2022-06-25 08:42:44",
            "updated_at": "2025-06-14 10:56:42"
        },
        "sub_category_id": null,
        "sub_category": null,
        "file_entities_count": 0,
        "file_entities": [],
        "category": null,
        "category_id": -1,
        "kb_tags": [],
        "kb_tag_ids": []
    }
}
```

## 新增

```javascript
POST https://{API_DOMAIN}/api/v1/kb
```

```javascript
curl -X POST
    -H "Content-Type: application/json"
    '{"subject": "如何設定產品", "content": "關於產品...." }'
    https://{API_HOST}/api/v1/kb
```

### Form Data

| 名稱          | 類型      | 必填 | 描述     | 範例           |
| ----------- | ------- | -- | ------ | ------------ |
| `subject`   | string  | 是  | 文章標題   | `"如何設定產品"`   |
| `content`   | string  | 是  | 文章內容   | `"關於產品...."` |
| `is_public` | boolean | 否  | 是否公開文章 | `false`      |

## 更新

```javascript
PUT https://{API_DOMAIN}/api/v1/kb/{kb}
```

```javascript
curl -X PUT
    -H "Content-Type: application/json"
    '{"subject": "如何設定產品", "content": "關於產品...." }'
    https://{API_HOST}/api/v1/kb/36
```


---

# 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://help.firstline.cc/developer/api/zhi-shi-ku.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.
