> For the complete documentation index, see [llms.txt](https://help.firstline.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.firstline.cc/developer/api/custom-table.md).

# 自訂表格

## 列出指定客戶自訂表格

```javascript
GET https://{API_HOST}/api/v1/contact/{contact}/contact-cz-relation
```

```javascript
curl -X GET
    -H "Content-Type: application/json:Authorization: Bearer eyJhbGciOiJIUzI1NiI..." https://{API_HOST}/api/v1/contact/1/contact-cz-relation?cz_col_category_id=5
```

### Parameters

<table data-header-hidden><thead><tr><th>PARAMETER</th><th width="111.51953125">REQUIRED</th><th width="110.4296875">DEFAULT</th><th width="120.15625">TYPE</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td>Parameter</td><td>Required</td><td>Default</td><td>Type</td><td>DESCRIPTION</td></tr><tr><td><strong>contact</strong></td><td>true</td><td></td><td>Number</td><td><a href="https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-contact">客戶</a> 的 ID</td></tr><tr><td><strong>cz_col_category_id</strong></td><td>false</td><td></td><td>Number</td><td>自訂欄位分類的 ID</td></tr><tr><td><strong>relation_search_cz_col_id</strong></td><td>false</td><td></td><td>Number</td><td>用於指定欲搜尋的「單一自訂表格欄位 ID」。</td></tr><tr><td><strong>relation_search_cz_col_op</strong></td><td>false</td><td></td><td>String</td><td>輸入 <code>like</code> 表示進行模糊比對搜尋。</td></tr><tr><td><strong>relation_search_cz_col_value</strong></td><td>false</td><td></td><td>String</td><td>指定要搜尋的欄位內容數值，根據 <strong><code>relation_search_cz_col_id</code></strong> 所對應的欄位進行比對。</td></tr></tbody></table>

&#x20;***請參考*** [***客戶自定關聯表格***](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-dong-tai-guan-lian-biao-ge-contactczrelation) ***回應格式***

```javascript

{
    "data": [
        {
            "id": 1,
            "relation_id": 1, // CzColCategory (自訂欄位分類) 的 id
            "relation_name": "健康檢查",
            "information": [
                {
                    "id": 1,
                    "value": 70,
                    "col_id": 1,
                    "col_name": "體重"
                },
                {
                    "id": 2,
                    "value": "A",
                    "col_id": 2,
                    "col_name": "血型"
                },
                {
                    "id": 3,
                    "value": [0,1],
                    "col_id": 3,
                    "col_name": "檢查項目"
                }
            ],
            "created_at": "2019-11-24 22:58:21",
            "updated_at": "2019-11-24 22:58:21"
        }
    ],
    "links": {
        "first": "https://firstline.localhost/api/contact/2197607/contact-cz-relation?page=1",
        "last": "https://firstline.localhost/api/contact/2197607/contact-cz-relation?page=1",
        "prev": null,
        "next": null
    },
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 1,
        "path": "https://firstline.localhost/api/contact/2197607/contact-cz-relation",
        "per_page": 15,
        "to": 1,
        "total": 1
    }
}
```

## 對指定客戶增加自訂表格紀錄&#x20;

```javascript
POST https://{API_HOST}/api/v1/contact/{contact}/cz-col-category/{cz_col_category}/contact-cz-relation
```

### URL Parameters

| PARAMETER             | REQUIRED | DEFAULT | TYPE   | DESCRIPTION                                                                                                           |
| --------------------- | -------- | ------- | ------ | --------------------------------------------------------------------------------------------------------------------- |
| **contact**           | true     | NULL    | Number | [客戶](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-contact) 的 id                              |
| **cz\_col\_category** | true     | NULL    | Number | [動態欄位分類](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#dong-tai-lan-wei-fen-lei-czcolcategory) 的 id |

### Form Data

| PARAMETER    | REQUIRED | DEFAULT | TYPE             | DESCRIPTION                |
| ------------ | -------- | ------- | ---------------- | -------------------------- |
| **cz\_cols** | false    | NULL    | Array or Objects | 動態欄位，參數型態參考 **CzCol** 表格說明 |

**Cz\_Col**

此欄位為包含以下格式之陣列

| PARAMETER | REQUIRED | DEFAULT | TYPE   | DESCRIPTION |
| --------- | -------- | ------- | ------ | ----------- |
| **id**    | true     | NULL    | Number | 動態欄位的 id    |
| **value** | true     | NULL    | String | 動態欄位的值      |

### Response

請參考 [客戶自訂表格](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-dong-tai-guan-lian-biao-ge-contactczrelation) 和 [客戶自訂表格內容](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-dong-tai-guan-lian-biao-ge-nei-rong-contactczrelationinformation) 回應格式

```javascript

{
    "data": [
        {
            "id": 2,
            "relation_id": 1, // CzColCategory (動態關聯分類) 的 id
            "relation_name": "健康檢查",
            "information": [
                {
                    "id": 4,
                    "value": 65,
                    "col_id": 1,
                    "col_name": "體重"
                },
                {
                    "id": 5,
                    "value": "A",
                    "col_id": 2,
                    "col_name": "血型"
                },
                {
                    "id": 6,
                    "value": [1,2],
                    "col_id": 3,
                    "col_name": "檢查項目"
                }
            ],
            "created_at": "2019-11-25 22:58:21",
            "updated_at": "2019-11-25 22:58:21"
        }
    ],
    "links": {
        "first": "https://firstline.localhost/api/contact/2197607/contact-cz-relation?page=1",
        "last": "https://firstline.localhost/api/contact/2197607/contact-cz-relation?page=1",
        "prev": null,
        "next": null
    },
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 1,
        "path": "https://firstline.localhost/api/contact/2197607/contact-cz-relation",
        "per_page": 15,
        "to": 2,
        "total": 2
    }
}
```

### **範例**

* id=1, type=1 (字串), name='體重'
* id=2, type=6 (單選), name='血型', options (選項)=\[{"text": "A型", "value":"A"},{"text": "B型", "value":"B"},{"text": "O型", "value":"O"},{"text": "AB型", "value":"AB"}]
* id=3, type=7 (多選), name='檢查項目', options (選項)=\[{"text": "X光", "value": 0}, {"text": "抽血", "value": 1}, {"text": "量身高", "value": 2}]

參數範例如下：(注意不論是**單選**還是**多選**，都是丟 value，若誤丟 text 會導致前端顯示出現問題)

```javascript
{
    "cz_cols": [
        {
            "id":1,
            "value":65
        },
        {
            "id":2,
            "value":"A"
        },
        {
            "id":3,
            "value":[1,2]
        }
    ]
}
```

> Form Data cz\_cols

```javascript
[
    {"id":1, "value":"65"}, // 1: 體重
    {"id":2, "value":"A"}, // 2: 血型
    {"id":3, "value": [1, 2]} // 3. 檢查項目: 抽血+量身高
]
```

## 對指定客戶更新自訂表格紀錄

```javascript
PUT https://{API_HOST}/api/v1/contact/{contact}/contact-cz-relation/{contact_cz_relation}
```

### URL Parameters

| PARAMETER                 | REQUIRED | DEFAULT | TYPE   | DESCRIPTION                                                                                                                         |
| ------------------------- | -------- | ------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------- |
| **contact**               | true     | NULL    | Number | [客戶](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-contact) 的 id                                            |
| **contact\_cz\_relation** | true     | NULL    | Number | [客戶動態關聯表格](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-dong-tai-guan-lian-biao-ge-contactczrelation) 的 id |

### Form Data

| PARAMETER    | REQUIRED | DEFAULT | TYPE  | DESCRIPTION                |
| ------------ | -------- | ------- | ----- | -------------------------- |
| **cz\_cols** | false    | NULL    | Array | 動態欄位，參數型態參考 **CzCol** 表格說明 |

#### **Cz\_Col**

此欄位為包含以下格式之陣列

| PARAMETER | REQUIRED | DEFAULT | TYPE   | DESCRIPTION |
| --------- | -------- | ------- | ------ | ----------- |
| **id**    | true     | NULL    | Number | 動態欄位的 id    |
| **value** | true     | NULL    | String | 動態欄位的值      |

### Response

請參考 [客戶動態關聯表格](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-dong-tai-guan-lian-biao-ge-contactczrelation) 回應格式

```javascript

{
    "data": {
        "id": 1,
        "relation_id": 1, // CzColCategory 的 id
        "relation_name": "寶寶資料",
        "information": [
            {
                "id": 4,
                "value": 55,
                "col_id": 1,
                "col_name": "體重"
            },
            {
                "id": 5,
                "value": "A",
                "col_id": 2,
                "col_name": "血型"
            },
            {
                "id": 6,
                "value": [1,2],
                "col_id": 3,
                "col_name": "檢查項目"
            }
        ]
    }
}
```

### **範例**

* id=1, type=1 (字串), name='體重'
* id=2, type=6 (單選), name='血型', options (選項)=\[{"text": "A型", "value":"A"},{"text": "B型", "value":"B"},{"text": "O型", "value":"O"},{"text": "AB型", "value":"AB"}]
* id=3, type=7 (多選), name='從事運動', options (選項)=\[{"text": "籃球", "value": 0}, {"text": "跑步", "value": 1}, {"text": "游泳", "value": 2}]

參數範例如下: (注意不論是**單選**還是**多選**，都是丟 value，若誤丟 text 會導致前端顯示出現問題)

```javascript

{
    "cz_cols": [
        {
            "id": 1, // 體重欄位的 id
            "value": 55
        }
    ]
}
```

> Form Data cz\_cols

```javascript
[
    {"id":1, "value":"70"}, // 1: 體重
    {"id":2, "value":"AB"}, // 2: 血型
    {"id":3, "value": [1, 2]} // 3. 運動: 跑步+游泳
]
```

## 對指定客戶刪除自訂表格紀錄

```javascript
DELETE https://{API_HOST}/api/v1/contact/{contact}/contact-cz-relation/{contact_cz_relation}
```

```javascript
curl -X DELETE
    -H "Content-Type: application/json:Authorization: Bearer eyJhbGciOiJIUzI1NiI..." https://{API_HOST}/api/v1/contact/1/contact-cz-relation/1
```

### URL Parameters

| PARAMETER                 | REQUIRED | DEFAULT | TYPE   | DESCRIPTION                                                                                                                         |
| ------------------------- | -------- | ------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------- |
| **contact**               | true     | NULL    | Number | [客戶](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-contact) 的 id                                            |
| **contact\_cz\_relation** | true     | NULL    | Number | [客戶動態關聯表格](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-dong-tai-guan-lian-biao-ge-contactczrelation) 的 id |

> 回應 204 http status

## 對指定客戶刪除指定分類的自訂表格紀錄

```javascript
DELETE https://{API_HOST}/api/v1/contact/{contact}/cz-col-category/{cz_col_category}
```

```javascript
curl -X DELETE
    -H "Content-Type: application/json:Authorization: Bearer eyJhbGciOiJIUzI1NiI..." https://{API_HOST}/api/v1/contact/1/cz-col-category/1
```

### URL Parameters

| PARAMETER             | REQUIRED | DEFAULT | TYPE   | DESCRIPTION                                                                              |
| --------------------- | -------- | ------- | ------ | ---------------------------------------------------------------------------------------- |
| **contact**           | true     | NULL    | Number | [客戶](https://help.firstline.cc/developer/api/hui-ying-wu-jian-ge-shi#ke-hu-contact) 的 id |
| **cz\_col\_category** | true     | NULL    | Number | [動態欄位分類](/developer/api/response-object.md#dong-tai-lan-wei-fen-lei-czcolcategory) 的 id  |

> 回應 204 http status
