# Leadtime

> Estimate the expected delivery time for a route before creating the order.

## Endpoint

| Environment | URL |
| --- | --- |
| Production | `https://online-gateway.ghn.vn/shiip/public-api/v2/shipping-order/leadtime` |
| Staging | `https://dev-online-gateway.ghn.vn/shiip/public-api/v2/shipping-order/leadtime` |

**Method**: `POST`

## Headers

| Header | Required | Description |
| --- | --- | --- |
| `Content-Type` | Yes | `application/json` |
| `Token` | Yes | Shop token (issued by GHN) — [get a token](https://developer.ghn.vn/en/docs/token/get-token.md) |
| `ShopId` | Yes | Shop ID (int) |

## Parameters

- **to_district_id** (Int): Delivery district ID (from [Get District](https://developer.ghn.vn/en/docs/master-data/get-district.md))
- **to_ward_code** (String): Delivery ward code (from [Get Ward](https://developer.ghn.vn/en/docs/master-data/get-ward.md))
- **from_district_id** (Int): Pickup district ID. Default: your shop's registered address
- **from_ward_code** (String): Pickup ward code. Default: your shop's registered address
- **service_type_id** (Int): Service type, chosen by weight:<br>`2`: total weight **under 20 kg**<br>`5`: total weight **20 kg or more**, or multi-parcel orders
- **weight** (Int): Weight (gram) — affects the estimate for heavy goods
- **length** (Int): Length (cm)
- **width** (Int): Width (cm)
- **height** (Int): Height (cm)

> **NOTE**
> Use `service_type_id`, not `service_id`. The api.ghn.vn page shows `service_id`, but it has no effect on the estimate.

## Request Example

```bash
curl -X POST https://dev-online-gateway.ghn.vn/shiip/public-api/v2/shipping-order/leadtime \
  -H "Token: 5c1d8a9e-2f4b-11ed-..." \
  -H "ShopId: 92837" \
  -H "Content-Type: application/json" \
  -d '{
    "from_district_id": 1452,
    "from_ward_code": "21007",
    "to_district_id": 1444,
    "to_ward_code": "20308",
    "service_type_id": 2
  }'
```

## Response

### Success (HTTP 200)

_Captured from a real Staging-environment call._

```json
{
  "code": 200,
  "message": "Success",
  "data": {
    "leadtime": 1784221199,
    "leadtime_order": {
      "from_estimate_date": "2026-07-16T16:59:59Z",
      "to_estimate_date": "2026-07-16T16:59:59Z"
    }
  }
}
```

### Response Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | Int | HTTP code (`200` on success) |
| `message` | String | Result message (`Success`) |
| `data.leadtime` | Int | Expected delivery time as a **Unix timestamp in seconds** (not an ISO date) |
| `data.leadtime_order.from_estimate_date` | String | Earliest expected delivery (ISO 8601) |
| `data.leadtime_order.to_estimate_date` | String | Latest expected delivery (ISO 8601) |

### Error — missing to_district_id (HTTP 400)

_Captured from a real Staging-environment call._

```json
{
  "code": 400,
  "message": "Key: 'myRequest.ToDistrictID' Error:Field validation for 'ToDistrictID' failed on the 'required' tag",
  "data": null,
  "code_message": "USER_ERR_COMMON",
  "code_message_value": "Sai thông tin đầu vào. Vui lòng thử lại."
}
```

## Error Codes

| code_message | HTTP | When |
| --- | --- | --- |
| `USER_ERR_COMMON` | 400 | Missing `to_district_id` / `to_ward_code`, or invalid input |
| `CLIENT_NOT_OWNER_OF_SHOP` | 400 | Token does not own the shop |
| `SERVER_ERROR_COMMON` | 500 | Internal error |
