# Thành phố, quận huyện

* /api/shipping/location: Lấy danh sách thành phố, quận huyện từ Nhanh.vn.
* Các API [thêm đơn hàng](/v2/order/add.md), [tính phí vận chuyển](https://github.com/nvndocs/docs-pos-openapi/blob/v2/docs/shipping/fee.md) sẽ cần sử dụng đến các dữ liệu này.
* Chú ý: Dữ liệu thành phố, quận huyện rất ít khi bị thay đổi (chỉ xảy ra khi có thay đổi tên, chia tách hoặc gộp 1 vài thành phố, quận huyện), bạn có thể cache dữ liệu trên hệ thống của bạn để giảm tải việc phải gọi API liên tục, thời gian cache khuyến cáo là 24h.

## Request

* Xem các [common request params](/v2/readme.md#request-params)
* Các key của mảng **data array** dùng để tạo **data** json string:

| Key      | Type   | Description                                                                                                                                                 |
| -------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type     | string | CITY/DISTRICT/WARD (mặc định là CITY)                                                                                                                       |
| parentId | int    | <p>Nếu type = DISTRICT thì parentId = id của thành phố cần lấy ra danh sách quận huyện.<br>Nếu type = WARD thì parentId = id của quận huyện cần lấy ra.</p> |

## Response

* JSON decode the response to get the structure:

| Key      | Type | Description                               |
| -------- | ---- | ----------------------------------------- |
| code     | int  | 1 = success or 0 = failed                 |
| messages | \[ ] | is an array of error messages if code = 0 |
| data     | \[ ] | Mảng danh sách thành phố hoặc quận huyện  |

* Nếu **type = CITY**

```javascript
data = [
    [
      "id": 2, // int
      "name":  "Hà Nội" // string
    ],
    [
      "id": 3,
      "name":  "Hồ Chí Minh"
    ],
    ...
]
```

* Nếu **type = DISTRICT**

```javascript
data = [
    [
      "id" => 2, // int
      "parentId" => 2, // int
      "name" => "Quận Hoàn Kiếm" // string
    ],
    [
      "id" => 6,
      "cityLocationId" => 2,
      "name" => "Quận Hai Bà Trưng"
    ],
    ...
]
```

* Nếu **type = WARD**

```javascript
data = [
    [
      "id" => 2, // int
      "parentId" => 3, // int
      "name" => "Phường Bạch Đằng" // string
    ],
    [
      "id" => 6,
      "parentId" => 3,
      "name" => "Phường Bách Khoa"
    ],
    ...
]
```


---

# 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://apidocs.nhanh.vn/v2/shipping/location.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.
