# 客戶匯入排程

## 新增

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

```javascript
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/entity-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 以下，支援 csv、xls 格式。 |

### Response

| Property | Type   | Description                                                                    |
| -------- | ------ | ------------------------------------------------------------------------------ |
| data     | Object | [匯入排程](https://help.firstline.cc/developer/response-object#entity-import-task) |

```javascript
{
    "data": {
        "id": 2,
        "has_header": false,
        "file": "entity-import/1615362223-import.csv",
        "size": 50,
        "total_amount": 3,
        "description": "dddd",
        "status": 2,
        "current_sheet_index": 1,
        "current_row_index": 3,
        "job_turns": 1,
        "executed_start_at": "2021-03-10 15:43:44",
        "executed_end_at": "2021-03-10 15:43:44",
        "recipe_id": 1,
        "creater_id": 1,
        "created_at": "2021-03-10 15:43:43",
        "updated_at": "2021-03-10 15:43:44",
        "error": null,
        "restart_at": null,
        "stop_at": null,
        "recipe": {
            "id": 1,
            "name": "ccc",
            "description": null,
            "headers": [
                {
                    "value": "contacts.first_name"
                },
                {
                    "value": "contacts.membership_no",
                    "text": "Customer Number"
                },
                {
                    "value": "phone_numbers.number",
                    "set_id": 1
                },
                {
                    "value": "email_contacts.address",
                    "set_id": 1
                }
            ],
            "unique_columns": [
                "phone_numbers.number",
                "email_contacts.address"
            ],
            "creater_id": 1,
            "created_at": "2021-03-10T07:38:52.000000Z",
            "updated_at": "2021-05-19T12:18:49.000000Z",
            "importable_type": "App\\Contact"
        }
    }
}
```

## 列表

### Http Request

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

```
curl -X GET
    -H "Content-Type: application/json"
    "https://{API_HOST}/api/v1/entity-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 | 匯入任務        |
| meta     | Object           | 頁籤物件        |

```javascript
    "data": [
        {
            "id": 4,
            "has_header": false,
            "file": "entity-import/1621426602-import.csv",
            "size": 49,
            "total_amount": 1,
            "description": "null",
            "status": 2,
            "current_sheet_index": 1,
            "current_row_index": 1,
            "job_turns": 1,
            "executed_start_at": "2021-05-19 20:16:43",
            "executed_end_at": "2021-05-19 20:16:44",
            "recipe_id": 1,
            "creater_id": 1,
            "created_at": "2021-05-19 20:16:42",
            "updated_at": "2021-05-19 20:16:44",
            "error": null,
            "restart_at": null,
            "stop_at": null,
            "recipe": {
                "id": 1,
                "name": "ccc",
                "description": null,
                "headers": [
                    {
                        "value": "contacts.first_name"
                    },
                    {
                        "value": "contacts.membership_no",
                        "text": "Customer Number"
                    },
                    {
                        "value": "phone_numbers.number",
                        "set_id": 1
                    },
                    {
                        "value": "email_contacts.address",
                        "set_id": 1
                    }
                ],
                "unique_columns": [
                    "phone_numbers.number",
                    "email_contacts.address"
                ],
                "creater_id": 1,
                "created_at": "2021-03-10T07:38:52.000000Z",
                "updated_at": "2021-05-19T12:18:49.000000Z",
                "importable_type": "App\\Contact"
            }
        },
        {
            "id": 3,
            "has_header": false,
            "file": "entity-import/1621426576-import.csv",
            "size": 49,
            "total_amount": 1,
            "description": "null",
            "status": 2,
            "current_sheet_index": 1,
            "current_row_index": 1,
            "job_turns": 1,
            "executed_start_at": "2021-05-19 20:16:19",
            "executed_end_at": "2021-05-19 20:16:19",
            "recipe_id": 1,
            "creater_id": 1,
            "created_at": "2021-05-19 20:16:16",
            "updated_at": "2021-05-19 20:16:19",
            "error": null,
            "restart_at": null,
            "stop_at": null,
            "recipe": {
                "id": 1,
                "name": "ccc",
                "description": null,
                "headers": [
                    {
                        "value": "contacts.first_name"
                    },
                    {
                        "value": "contacts.membership_no",
                        "text": "Customer Number"
                    },
                    {
                        "value": "phone_numbers.number",
                        "set_id": 1
                    },
                    {
                        "value": "email_contacts.address",
                        "set_id": 1
                    }
                ],
                "unique_columns": [
                    "phone_numbers.number",
                    "email_contacts.address"
                ],
                "creater_id": 1,
                "created_at": "2021-03-10T07:38:52.000000Z",
                "updated_at": "2021-05-19T12:18:49.000000Z",
                "importable_type": "App\\Contact"
            }
        },
        {
            "id": 2,
            "has_header": false,
            "file": "entity-import/1615362223-import.csv",
            "size": 50,
            "total_amount": 3,
            "description": "dddd",
            "status": 2,
            "current_sheet_index": 1,
            "current_row_index": 3,
            "job_turns": 1,
            "executed_start_at": "2021-03-10 15:43:44",
            "executed_end_at": "2021-03-10 15:43:44",
            "recipe_id": 1,
            "creater_id": 1,
            "created_at": "2021-03-10 15:43:43",
            "updated_at": "2021-03-10 15:43:44",
            "error": null,
            "restart_at": null,
            "stop_at": null,
            "recipe": {
                "id": 1,
                "name": "ccc",
                "description": null,
                "headers": [
                    {
                        "value": "contacts.first_name"
                    },
                    {
                        "value": "contacts.membership_no",
                        "text": "Customer Number"
                    },
                    {
                        "value": "phone_numbers.number",
                        "set_id": 1
                    },
                    {
                        "value": "email_contacts.address",
                        "set_id": 1
                    }
                ],
                "unique_columns": [
                    "phone_numbers.number",
                    "email_contacts.address"
                ],
                "creater_id": 1,
                "created_at": "2021-03-10T07:38:52.000000Z",
                "updated_at": "2021-05-19T12:18:49.000000Z",
                "importable_type": "App\\Contact"
            }
        }
    ],
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 1,
        "per_page": 15,
        "to": 3,
        "total": 3
    }
}
```

## 檢視

### Http Request

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

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

### Response

| Property | Type   | Description                                                                    |
| -------- | ------ | ------------------------------------------------------------------------------ |
| data     | Object | [匯入排程](https://help.firstline.cc/developer/response-object#entity-import-task) |

```javascript
{
    "data": {
        "id": 2,
        "has_header": false,
        "file": "entity-import/1615362223-import.csv",
        "size": 50,
        "total_amount": 3,
        "description": "dddd",
        "status": 2,
        "current_sheet_index": 1,
        "current_row_index": 3,
        "job_turns": 1,
        "executed_start_at": "2021-03-10 15:43:44",
        "executed_end_at": "2021-03-10 15:43:44",
        "recipe_id": 1,
        "creater_id": 1,
        "created_at": "2021-03-10 15:43:43",
        "updated_at": "2021-03-10 15:43:44",
        "error": null,
        "restart_at": null,
        "stop_at": null,
        "recipe": {
            "id": 1,
            "name": "ccc",
            "description": null,
            "headers": [
                {
                    "value": "contacts.first_name"
                },
                {
                    "value": "contacts.membership_no",
                    "text": "Customer Number"
                },
                {
                    "value": "phone_numbers.number",
                    "set_id": 1
                },
                {
                    "value": "email_contacts.address",
                    "set_id": 1
                }
            ],
            "unique_columns": [
                "phone_numbers.number",
                "email_contacts.address"
            ],
            "creater_id": 1,
            "created_at": "2021-03-10T07:38:52.000000Z",
            "updated_at": "2021-05-19T12:18:49.000000Z",
            "importable_type": "App\\Contact"
        }
    }
}
```

## 範本列表

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

### Http Request

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

```
curl -X GET
    -H "Content-Type: application/json"
    "https://{API_HOST}/api/v1/entity-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": "ccc",
            "importable_type": "App\\Contact",
            "description": null,
            "headers": [
                {
                    "value": "contacts.first_name"
                },
                {
                    "value": "contacts.membership_no",
                    "text": "Customer Number"
                },
                {
                    "value": "phone_numbers.number",
                    "set_id": 1
                },
                {
                    "value": "email_contacts.address",
                    "set_id": 1
                }
            ],
            "unique_columns": [
                "phone_numbers.number",
                "email_contacts.address"
            ],
            "creater_id": 1,
            "creater": {
                "id": 1,
                "name": "洪 小閎",
                "first_name": "洪",
                "last_name": "小閎",
                "employee_no": "jocoonopa",
                "photo_url": null,
                "identity_no": "A125202038",
                "job_title_id": -1,
                "department_id": -1,
                "extension_id": -1,
                "extension": null,
                "profile_id": 1,
                "group_id": null,
                "group": {
                    "id": null,
                    "name": null,
                    "description": null,
                    "supervisor_id": null
                },
                "cti_agent_account": null,
                "cti_agent": null,
                "cti_agent_id": null,
                "created_at": "2021-01-15 10:53:00",
                "updated_at": "2021-08-05 02:38:09"
            },
            "tasks_count": 13
        }
    ],
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 1,
        "per_page": 15,
        "to": 1,
        "total": 1
    }
}
```

## 範本檢視

### Http Request

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

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

### URL Parameters

| Parameter | Description |
| --------- | ----------- |
| id        | 批次匯入範本 ID   |

### Response

```javascript
{
    "data": {
        "id": 1,
        "name": "ccc",
        "importable_type": "App\\Contact",
        "description": null,
        "headers": [
            {
                "value": "contacts.first_name"
            },
            {
                "value": "contacts.membership_no",
                "text": "Customer Number"
            },
            {
                "value": "phone_numbers.number",
                "set_id": 1
            },
            {
                "value": "email_contacts.address",
                "set_id": 1
            }
        ],
        "unique_columns": [
            "phone_numbers.number",
            "email_contacts.address"
        ],
        "creater_id": 1,
        "creater": {
            "id": 1,
            "name": "洪 小閎",
            "first_name": "洪",
            "last_name": "小閎",
            "employee_no": "jocoonopa",
            "photo_url": null,
            "identity_no": "A125202038",
            "job_title_id": -1,
            "department_id": -1,
            "extension_id": -1,
            "extension": null,
            "profile_id": 1,
            "group_id": null,
            "group": {
                "id": null,
                "name": null,
                "description": null,
                "supervisor_id": null
            },
            "cti_agent_account": null,
            "cti_agent": null,
            "cti_agent_id": null,
            "created_at": "2021-01-15 10:53:00",
            "updated_at": "2021-08-05 02:38:09"
        },
        "tasks_count": 13
    }
}
```


---

# 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-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.
