# Print Order

## Endpoint

| Environment | URL |
| --- | --- |
| Production | `https://online-gateway.ghn.vn/shiip/public-api/v2/a5/gen-token` |
| Staging | `https://dev-online-gateway.ghn.vn/shiip/public-api/v2/a5/gen-token` |

**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

- **order_codes** (String[]): GHN tracking codes to include in the print token. **Max 10,000** per request. Every code must be an existing order that belongs to your account — **all-or-nothing**: one unknown or non-owned code fails the whole request and no token is issued
- **item_index** (Int[]): For multi-item orders: the positions (0-based) of the items to print. Default: all items

## Request Example

```bash
curl -X POST https://dev-online-gateway.ghn.vn/shiip/public-api/v2/a5/gen-token \
  -H "Token: 5c1d8a9e-2f4b-11ed-..." \
  -H "ShopId: 92837" \
  -H "Content-Type: application/json" \
  -d '{
    "order_codes": ["LADT8L", "LADFYR"]
  }'
```

## Response

### Success (HTTP 200)

_Captured from a real Staging-environment call._

```json
{
  "code": 200,
  "message": "Success",
  "data": {
    "token": "1b744cae-8005-11f1-b50f-ba37616041ec"
  }
}
```

### Response Fields

| Field | Type | Description |
| --- | --- | --- |
| `code` | Int | HTTP code (`200` on success) |
| `message` | String | Result message (`Success`) |
| `data.token` | String | Print token for the requested orders. Append it to a print URL below to open the printable labels |

### Using the token

Open the printable labels by appending the token to one of these URLs (the pages are served by GHN's print system). Pick the paper size you need:

| Size | Production URL |
| --- | --- |
| A5 | `https://online-gateway.ghn.vn/a5/public-api/printA5?token=<token>` |
| 80×80 mm | `https://online-gateway.ghn.vn/a5/public-api/print80x80?token=<token>` |
| 52×70 mm | `https://online-gateway.ghn.vn/a5/public-api/print52x70?token=<token>` |

On Staging, use the same paths on `https://dev-online-gateway.ghn.vn`. The token expires after about **30 minutes** — generate it right before printing.

### Error — order not found / not yours (HTTP 400)

_Captured from a real Staging-environment call (unknown order code)._ All-or-nothing: one bad code aborts the whole request with `data: null` — no token is issued.

```json
{
  "code": 400,
  "message": "Lỗi gọi API: corev2_tenant_order_detail - Đơn hàng không tồn tại",
  "data": null,
  "code_message": "ORDER_NOT_FOUND",
  "code_message_value": "Không tìm thấy thông tin đơn hàng. Vui lòng thử lại sau."
}
```

## Error Codes

| code_message | HTTP | When |
| --- | --- | --- |
| `ORDER_NOT_FOUND` | 400 | An order code is unknown or does not belong to your account. The whole batch is aborted; no token is issued |
| `CLIENT_NOT_OWNER_OF_SHOP` | 400 | An order belongs to a shop your account is not a member of |
| Over-limit (`Not support over 10000 orders`) | 400 | More than 10,000 codes in one request |
| `SERVER_ERROR_COMMON` | 500 | Internal error |
