# 地址

## 通用資料

此區為聯絡地址欄位對應資料。

### 類別 type

| 名稱     | 值 |
| ------ | - |
| **住家** | 0 |
| **通訊** | 1 |
| **帳單** | 2 |
| **郵寄** | 3 |
| **戶籍** | 4 |
| **其他** | 5 |

## 搜尋聯絡地址

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

```javascript
curl -X GET
    -H "Content-Type: application/json"
    '{"city_id":1}'
    https://{API_HOST}/api/v1/address
```

### Form Data

下表為可使用的過濾條件

| PARAMETER       | REQUIRED | DEFAULT | TYPE   | DESCRIPTION                   |
| --------------- | -------- | ------- | ------ | ----------------------------- |
| **contact\_id** | false    | NULL    | Number | 客戶的 id                        |
| **type**        | false    | NULL    | Number | 0:住家,1:通訊,2:帳單,3:郵寄,4:戶籍,5:其他 |
| **address**     | false    | NULL    | String | 地址                            |
| **country\_id** | false    | NULL    | Number | 國家的id                         |
| **state\_id**   | false    | NULL    | Number | 城市的id                         |
| **city\_id**    | false    | NULL    | Number | 區域的id                         |
| **description** | false    | NULL    | String | 地址描述                          |

### Response

| PROPERTY | TYPE             | DESCRIPTION                                                         |
| -------- | ---------------- | ------------------------------------------------------------------- |
| data     | Array of objects | [地址陣列](https://help.firstline.cc/developer/response-object#address) |
| meta     | Object           | Pagination meta                                                     |

```javascript

{
    "data": [
        {
            "id": 2678,
            "type": 1,
            "enum_type": {
                "key": "MAILING",
                "value": 1,
                "description": "mail address"
            },
            "address": "基隆市仁愛區愛一路35號8樓之一",
            "contact_id": 1938277,
            "profile_id": 1938247,
            "state": {
                "id": 2,
                "country_id": 1,
                "name": "基隆市"
            },
            "state_id": 2,
            "country": {
                "id": 1,
                "name": "台灣",
                "abbrev": null
            },
            "country_id": 1,
            "city": {
                "id": 1,
                "state_id": 2,
                "name": "仁愛區",
                "zipcode": "200"
            },
            "city_id": 1,
            "description": null
        },
        {
            "id": 2830,
            "type": 1,
            "enum_type": {
                "key": "MAILING",
                "value": 1,
                "description": "mail address"
            },
            "address": "愛一路19號",
            "contact_id": 1938482,
            "profile_id": 1938452,
            "state": {
                "id": 2,
                "country_id": 1,
                "name": "基隆市"
            },
            "state_id": 2,
            "country": {
                "id": 1,
                "name": "台灣",
                "abbrev": null
            },
            "country_id": 1,
            "city": {
                "id": 1,
                "state_id": 2,
                "name": "仁愛區",
                "zipcode": "200"
            },
            "city_id": 1,
            "description": null
        }
    ],
    "links": {
        "first": "https://firstline.localhost/api/address?per_page=2&city_id=1&page=1",
        "last": "https://firstline.localhost/api/address?per_page=2&city_id=1&page=63",
        "prev": null,
        "next": "https://firstline.localhost/api/address?per_page=2&city_id=1&page=2"
    },
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 63,
        "path": "https://firstline.localhost/api/address",
        "per_page": "2",
        "to": 2,
        "total": 126
    }
}
```

## 取得指定客戶聯絡地址

## 取得指定聯絡地址

```javascript
https://{API_DOMAIN}/api/v1/address/{address}
```

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

### URL Parameters

| PARAMETER   | REQUIRED | DEFAULT | TYPE   | DESCRIPTION                                                            |
| ----------- | -------- | ------- | ------ | ---------------------------------------------------------------------- |
| **address** | True     | Null    | Number | [地址](https://help.firstline.cc/developer/response-object#address) 的 id |

### Response

請參考[地址](https://help.firstline.cc/developer/response-object#address)回應格式

| PROPERTY | TYPE   | DESCRIPTION                                                       |
| -------- | ------ | ----------------------------------------------------------------- |
| **data** | Object | [地址](https://help.firstline.cc/developer/response-object#address) |

```javascript

{
    "data": {
        "id": 1,
        "type": 3,
        "address": "67, rue Michelle Jones\n81785 Berge",
        "profile_id": 1,
        "state": {
            "id": 1,
            "country_id": 1,
            "name": "台北市"
        },
        "state_id": 1,
        "country": {
            "id": 1,
            "name": "台灣",
            "abbrev": null
        },
        "country_id": 1,
        "city": {
            "id": 1,
            "state_id": 1,
            "name": "仁愛區",
            "zipcode": "200"
        },
        "city_id": 1,
        "description": null
    }
}

```

## 新增指定客戶聯絡地址

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

```javascript
curl -X POST
    -H "Content-Type: application/json"
    '{"profile_id":1,"country_id":1,"state_id":1,"city_id":1,"address": "67, rue Michelle Jones 81785 Berge"}'
    https://{API_HOST}/api/v1/address
```

### Form Data

| PARAMETER       | REQUIRED | DEFAULT | TYPE   | DESCRIPTION                   |
| --------------- | -------- | ------- | ------ | ----------------------------- |
| **contact\_id** | true     | NULL    | Number | 客戶的 id                        |
| **type**        | true     | NULL    | Number | 0:住家,1:郵寄,2:帳單,3:快遞,4:現居,5:其他 |
| **address**     | true     | NULL    | String | 地址                            |
| **country\_id** | false    | NULL    | Number | 國家的id                         |
| **state\_id**   | false    | NULL    | Number | 城市的id                         |
| **city\_id**    | false    | NULL    | Number | 區域的id                         |
| **description** | false    | NULL    | String | 地址描述                          |

### Response

```javascript
{
    "data": {
        "id": 1,
        "type": 3,
        "address": "67, rue Michelle Jones\n81785 Berge",
        "profile_id": 1,
        "state": {
            "id": 1,
            "country_id": 1,
            "name": "台北市"
        },
        "state_id": 1,
        "country": {
            "id": 1,
            "name": "台灣",
            "abbrev": null
        },
        "country_id": 1,
        "city": {
            "id": 1,
            "state_id": 1,
            "name": "仁愛區",
            "zipcode": "200"
        },
        "city_id": 1,
        "description": null
    }
}
```

## 修改聯絡地址

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

```javascript
curl -X PUT
    -H "Content-Type: application/json"
    '{"address": "仁愛路一段"}'
    https://{API_HOST}/api/v1/address/1
```

### URL Parameters

| PARAMETER   | REQUIRED | DEFAULT | TYPE   | DESCRIPTION |
| ----------- | -------- | ------- | ------ | ----------- |
| **address** | true     | NULL    | Number | 地址的id       |

### Form Data

| PARAMETER       | REQUIRED | DEFAULT | TYPE   | DESCRIPTION                   |
| --------------- | -------- | ------- | ------ | ----------------------------- |
| **contact\_id** | false    | NULL    | Number | 客戶的 id                        |
| **type**        | false    | NULL    | Number | 0:住家,1:郵寄,2:帳單,3:快遞,4:現居,5:其他 |
| **address**     | false    | NULL    | String | 地址                            |
| **country\_id** | false    | NULL    | Number | 國家的id                         |
| **state\_id**   | false    | NULL    | Number | 城市的id                         |
| **city\_id**    | false    | NULL    | Number | 區域的id                         |
| **description** | false    | NULL    | String | 地址描述                          |

### Response

請參考[地址](https://help.firstline.cc/developer/response-object#address)回應格式

```javascript
{
    "data": {
        "id": 1,
        "type": 3,
        "address": "信義路一段",
        "profile_id": 1,
        "state": {
            "id": 1,
            "country_id": 1,
            "name": "台北市"
        },
        "state_id": 1,
        "country": {
            "id": 1,
            "name": "台灣",
            "abbrev": null
        },
        "country_id": 1,
        "city": {
            "id": 1,
            "state_id": 1,
            "name": "仁愛區",
            "zipcode": "200"
        },
        "city_id": 1,
        "description": null
    }
}
```

## 刪除聯絡地址

Http status 為 204

```javascript
DELETE https://{API_DOMAIN}/api/v1/address/{address}
```

```javascript
curl -X DELETE
    -H "Content-Type: application/json"
    https://{API_HOST}/api/v1/address/1
```

### URL Parameters

| PARAMETER   | REQUIRED | DEFAULT | TYPE   | DESCRIPTION |
| ----------- | -------- | ------- | ------ | ----------- |
| **address** | true     | NULL    | Number | 地址的id       |

> 回傳 json 格式

```
{}
```
