# 客戶自訂表格匯入排程

## 新增

`POST https://{API_HOST}/api/v1/relation-import-task`

```
curl -X POST
    '{"recipe_id":5,"has_header":0,"description":"test upload"}'
    -H "Content-Type: application/json"
    -F file=@/home/user/import.csv
    "https://{API_HOST}/api/v1/relation-import-task"
```

### Request params

| Parameter   | Required | Default | Type    | Description        |
| ----------- | -------- | ------- | ------- | ------------------ |
| recipe\_id  | true     | NULL    | Number  | 欲使用的自訂表格匯入範本 id    |
| has\_header | false    | false   | Boolean | 是否忽略第一行表頭          |
| description | false    | NULL    | String  | 任務說明               |
| file        | true     | NULL    | binary  | 上傳匯入的檔案 (100MB 以下) |

### Response

| Property | Type   | Description                                                                                         |
| -------- | ------ | --------------------------------------------------------------------------------------------------- |
| data     | Object | [自訂表格匯入排程](/developer/api/response-object.md#zi-ding-biao-ge-hui-ru-pai-cheng-relation-import-task) |

```javascript
{
    "data": {
        "id": 4,
        "has_header": 0,
        "file": "relation-import/1629345399-ct匯入.csv",
        "size": 44,
        "total_amount": 3,
        "description": "dddd",
        "status": 2,
        "current_sheet_index": 1,
        "current_row_index": 3,
        "job_turns": 1,
        "executed_start_at": "2021-08-19 11:56:39",
        "executed_end_at": "2021-08-19 11:56:40",
        "recipe_id": 1,
        "creater_id": 1,
        "error": null,
        "created_at": "2021-08-19T03:56:39.000000Z",
        "updated_at": "2021-08-19T03:56:40.000000Z",
        "restart_at": null,
        "recipe": {
            "id": 1,
            "name": "客戶ct檢測匯入",
            "description": null,
            "headers": [
                {
                    "value": "contacts.membership_no"
                },
                {
                    "id": 11,
                    "type": 0,
                    "value": "cz_relation_information.11",
                    "text": "測量數字",
                    "isMatchField": true,
                    "category_id": 5
                }
            ],
            "unique_columns": [
                "contacts.membership_no"
            ],
            "relation_unique_column": "-1",
            "creater_id": 1,
            "cz_col_category_id": 5,
            "created_at": "2021-08-18T05:56:20.000000Z",
            "updated_at": "2021-08-18T05:56:20.000000Z",
            "importable_type": "App\\Contact",
            "cz_col_category": {
                "id": 5,
                "name": "ct值",
                "description": null,
                "creater_id": null,
                "created_at": "2021-08-18T05:51:16.000000Z",
                "updated_at": "2021-08-18T05:51:16.000000Z",
                "type": 1
            }
        }
    }
}
```

## 列表

### Http Request

`GET https://{API_HOST}/api/v1/relation-import-task`

```
curl -X GET
    -H "Content-Type: application/json"
    "https://{API_HOST}/api/v1/relation-import-task?per_page=15&page=1"
```

| Parameter | Required | Default | Type   | Description |
| --------- | -------- | ------- | ------ | ----------- |
| page      | false    | 1       | Number | 目前在第幾頁      |
| per\_page | false    | 15      | Number | 每頁呈現多少筆     |

### Response

| Property | Type             | Description                                                                                         |
| -------- | ---------------- | --------------------------------------------------------------------------------------------------- |
| data     | Array of objects | [自訂表格匯入排程](/developer/api/response-object.md#zi-ding-biao-ge-hui-ru-pai-cheng-relation-import-task) |
| meta     | Object           | Pagination meta                                                                                     |

```javascript
{
    "data": [
        {
            "id": 3,
            "has_header": 0,
            "file": "relation-import/1629266607-ct匯入.csv",
            "size": 44,
            "total_amount": 3,
            "description": "dddd",
            "status": 2,
            "current_sheet_index": 1,
            "current_row_index": 3,
            "job_turns": 1,
            "executed_start_at": "2021-08-18 14:03:27",
            "executed_end_at": "2021-08-18 14:03:27",
            "recipe_id": 1,
            "creater_id": 1,
            "error": null,
            "created_at": "2021-08-18T06:03:27.000000Z",
            "updated_at": "2021-08-18T06:03:27.000000Z",
            "restart_at": null,
            "recipe": {
                "id": 1,
                "name": "客戶ct檢測匯入",
                "description": null,
                "headers": [
                    {
                        "value": "contacts.membership_no"
                    },
                    {
                        "id": 11,
                        "type": 0,
                        "value": "cz_relation_information.11",
                        "text": "測量數字",
                        "isMatchField": true,
                        "category_id": 5
                    }
                ],
                "unique_columns": [
                    "contacts.membership_no"
                ],
                "relation_unique_column": "-1",
                "creater_id": 1,
                "cz_col_category_id": 5,
                "created_at": "2021-08-18T05:56:20.000000Z",
                "updated_at": "2021-08-18T05:56:20.000000Z",
                "importable_type": "App\\Contact",
                "cz_col_category": {
                    "id": 5,
                    "name": "ct值",
                    "description": null,
                    "creater_id": null,
                    "created_at": "2021-08-18T05:51:16.000000Z",
                    "updated_at": "2021-08-18T05:51:16.000000Z",
                    "type": 1
                }
            }
        },
        {
            "id": 2,
            "has_header": 0,
            "file": "relation-import/1629266289-ct匯入.csv",
            "size": 41,
            "total_amount": 3,
            "description": "null",
            "status": 2,
            "current_sheet_index": 1,
            "current_row_index": 3,
            "job_turns": 1,
            "executed_start_at": "2021-08-18 13:58:11",
            "executed_end_at": "2021-08-18 13:58:11",
            "recipe_id": 1,
            "creater_id": 1,
            "error": null,
            "created_at": "2021-08-18T05:58:09.000000Z",
            "updated_at": "2021-08-18T05:58:11.000000Z",
            "restart_at": null,
            "recipe": {
                "id": 1,
                "name": "客戶ct檢測匯入",
                "description": null,
                "headers": [
                    {
                        "value": "contacts.membership_no"
                    },
                    {
                        "id": 11,
                        "type": 0,
                        "value": "cz_relation_information.11",
                        "text": "測量數字",
                        "isMatchField": true,
                        "category_id": 5
                    }
                ],
                "unique_columns": [
                    "contacts.membership_no"
                ],
                "relation_unique_column": "-1",
                "creater_id": 1,
                "cz_col_category_id": 5,
                "created_at": "2021-08-18T05:56:20.000000Z",
                "updated_at": "2021-08-18T05:56:20.000000Z",
                "importable_type": "App\\Contact",
                "cz_col_category": {
                    "id": 5,
                    "name": "ct值",
                    "description": null,
                    "creater_id": null,
                    "created_at": "2021-08-18T05:51:16.000000Z",
                    "updated_at": "2021-08-18T05:51:16.000000Z",
                    "type": 1
                }
            }
        },
        {
            "id": 1,
            "has_header": 0,
            "file": "relation-import/1629266192-ct匯入.csv",
            "size": 41,
            "total_amount": 3,
            "description": "null",
            "status": 2,
            "current_sheet_index": 1,
            "current_row_index": 3,
            "job_turns": 1,
            "executed_start_at": "2021-08-18 13:56:34",
            "executed_end_at": "2021-08-18 13:56:35",
            "recipe_id": 1,
            "creater_id": 1,
            "error": null,
            "created_at": "2021-08-18T05:56:32.000000Z",
            "updated_at": "2021-08-18T05:56:35.000000Z",
            "restart_at": null,
            "recipe": {
                "id": 1,
                "name": "客戶ct檢測匯入",
                "description": null,
                "headers": [
                    {
                        "value": "contacts.membership_no"
                    },
                    {
                        "id": 11,
                        "type": 0,
                        "value": "cz_relation_information.11",
                        "text": "測量數字",
                        "isMatchField": true,
                        "category_id": 5
                    }
                ],
                "unique_columns": [
                    "contacts.membership_no"
                ],
                "relation_unique_column": "-1",
                "creater_id": 1,
                "cz_col_category_id": 5,
                "created_at": "2021-08-18T05:56:20.000000Z",
                "updated_at": "2021-08-18T05:56:20.000000Z",
                "importable_type": "App\\Contact",
                "cz_col_category": {
                    "id": 5,
                    "name": "ct值",
                    "description": null,
                    "creater_id": null,
                    "created_at": "2021-08-18T05:51:16.000000Z",
                    "updated_at": "2021-08-18T05:51:16.000000Z",
                    "type": 1
                }
            }
        }
    ],
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 1,
        "path": "https://firstline.localhost/api/v1/relation-import-task",
        "per_page": 15,
        "to": 3,
        "total": 3
    }
}
```

## 檢視

### Http Request

`GET https://{API_HOST}/api/v1/relation-import-task/{id}`

```
curl -X GET
    -H "Content-Type: application/json"
    "https://{API_HOST}/api/v1//relation-import-task/{id}"
```

### Response

| Property | Type   | Description                                                                                         |
| -------- | ------ | --------------------------------------------------------------------------------------------------- |
| data     | Object | [自訂表格匯入排程](/developer/api/response-object.md#zi-ding-biao-ge-hui-ru-pai-cheng-relation-import-task) |

```javascript
{
    "data": {
        "id": 4,
        "has_header": 0,
        "file": "relation-import/1629345399-ct匯入.csv",
        "size": 44,
        "total_amount": 3,
        "description": "dddd",
        "status": 2,
        "current_sheet_index": 1,
        "current_row_index": 3,
        "job_turns": 1,
        "executed_start_at": "2021-08-19 11:56:39",
        "executed_end_at": "2021-08-19 11:56:40",
        "recipe_id": 1,
        "creater_id": 1,
        "error": null,
        "created_at": "2021-08-19T03:56:39.000000Z",
        "updated_at": "2021-08-19T03:56:40.000000Z",
        "restart_at": null,
        "recipe": {
            "id": 1,
            "name": "客戶ct檢測匯入",
            "description": null,
            "headers": [
                {
                    "value": "contacts.membership_no"
                },
                {
                    "id": 11,
                    "type": 0,
                    "value": "cz_relation_information.11",
                    "text": "測量數字",
                    "isMatchField": true,
                    "category_id": 5
                }
            ],
            "unique_columns": [
                "contacts.membership_no"
            ],
            "relation_unique_column": "-1",
            "creater_id": 1,
            "cz_col_category_id": 5,
            "created_at": "2021-08-18T05:56:20.000000Z",
            "updated_at": "2021-08-18T05:56:20.000000Z",
            "importable_type": "App\\Contact",
            "cz_col_category": {
                "id": 5,
                "name": "ct值",
                "description": null,
                "creater_id": null,
                "created_at": "2021-08-18T05:51:16.000000Z",
                "updated_at": "2021-08-18T05:51:16.000000Z",
                "type": 1
            }
        }
    }
}
```

## 範本列表

{% hint style="info" %}
你可以透過 API 查找排程符合的範本 ID，或是透過系統介面查詢相關資訊。
{% endhint %}

### Http Request

`GET https://{API_HOST}/api/v1/relation-import-recipe?importable_type=App\Contact`

```
curl -X GET
    -H "Content-Type: application/json"
    "https://{API_HOST}/api/v1/relation-import-recipe?importable_type=App\Contact"
```

### Query Parameters

| Parameter        | Required | Default | Type   | Description            |
| ---------------- | -------- | ------- | ------ | ---------------------- |
| page             | false    | 1       | Number | 目前在第幾頁                 |
| per\_page        | false    | 15      | Number | 每頁呈現多少筆                |
| importable\_type | true     | NULL    | String | 範本類型，這邊需帶入 App\Contact |

### Response

```javascript
{
    "data": [
        {
            "id": 1,
            "name": "就診紀錄",
            "importable_type": "App\\Contact",
            "description": null,
            "headers": [
                {
                    "value": "contacts.identity_no"
                },
                {
                    "value": "cz_relation_information.9"
                },
                {
                    "value": "cz_relation_information.10"
                },
                {
                    "value": "cz_relation_information.11"
                }
            ],
            "cz_col_category_id": 7,
            "cz_col_category": {
                "id": 7,
                "name": "療程紀錄",
                "type": 1,
                "description": null,
                "creater_id": null
            },
            "unique_columns": [
                "contacts.identity_no"
            ],
            "relation_unique_column": "9",
            "creater_id": 2,
            "creater": {
                "id": 2,
                "name": "eason d",
                "first_name": "eason",
                "last_name": "d",
                "employee_no": "eason",
                "photo_url": "/employee/2/photo?t=1629339225",
                "identity_no": null,
                "job_title_id": -1,
                "department_id": 1,
                "extension_id": 2,
                "extension": {
                    "id": 2,
                    "type": 3,
                    "extension": "8002",
                    "webrtc_password": "540939228002",
                    "description": null,
                    "media_cluster_id": null
                },
                "profile_id": 284,
                "group_id": 2,
                "group": {
                    "id": 2,
                    "name": "業務團隊",
                    "description": null,
                    "supervisor_id": 26
                },
                "cti_agent_account": "ag8002",
                "cti_agent": {
                    "id": 2,
                    "account": "ag8002",
                    "group_id": null
                },
                "cti_agent_id": 2,
                "created_at": "2018-11-09 13:21:17",
                "updated_at": "2021-07-28 15:29:39"
            },
            "tasks_count": 6
        }
    ],
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 1,
        "per_page": 15,
        "to": 1,
        "total": 1
    }
}
```

## 範本檢視

### Http Request

`GET https://{API_HOST}/api/v1/relation-import-recipe/{id}`

```
curl -X GET
    -H "Content-Type: application/json"
    "https://{API_HOST}/api/v1/relation-import-recipe/1"
```

### URL Parameters

| Parameter | Description   |
| --------- | ------------- |
| id        | 自訂表格批次匯入範本 id |

### Response

```javascript
{
    "data": {
        "id": 1,
        "name": "就診紀錄",
        "importable_type": "App\\Contact",
        "description": null,
        "headers": [
            {
                "value": "contacts.identity_no"
            },
            {
                "value": "cz_relation_information.9"
            },
            {
                "value": "cz_relation_information.10"
            },
            {
                "value": "cz_relation_information.11"
            }
        ],
        "cz_col_category_id": 7,
        "cz_col_category": {
            "id": 7,
            "name": "療程紀錄",
            "type": 1,
            "description": null,
            "creater_id": null
        },
        "unique_columns": [
            "contacts.identity_no"
        ],
        "relation_unique_column": "9",
        "creater_id": 2,
        "creater": {
            "id": 2,
            "name": "eason d",
            "first_name": "eason",
            "last_name": "d",
            "employee_no": "eason",
            "photo_url": "/employee/2/photo?t=1629339612",
            "identity_no": null,
            "job_title_id": -1,
            "department_id": 1,
            "extension_id": 2,
            "extension": {
                "id": 2,
                "type": 3,
                "extension": "8002",
                "webrtc_password": "540939228002",
                "description": null,
                "media_cluster_id": null
            },
            "profile_id": 284,
            "group_id": 2,
            "group": {
                "id": 2,
                "name": "業務團隊",
                "description": null,
                "supervisor_id": 26
            },
            "cti_agent_account": "ag8002",
            "cti_agent": {
                "id": 2,
                "account": "ag8002",
                "group_id": null
            },
            "cti_agent_id": 2,
            "created_at": "2018-11-09 13:21:17",
            "updated_at": "2021-07-28 15:29:39"
        },
        "tasks_count": 6
    }
}
```


---

# 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/contact-import-table-task.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.
