B2E TSMC THSR Booking API
Session Exchange 換票 Token 與 Orders 訂單送交 ERP 之 Server-to-Server OpenAPI 規格書。
Api-Keybooking_access_tokenAPI 端點規範 (Endpoints)
Send the handoff JWT as `Authorization: Bearer <jwt>`, or JSON body `handoff_token` (header wins). Each handoff JWT (`jti`) can be exchanged once.
請求參數 (Headers / Parameters)
| 參數名稱 | 位置 | 必要性 | 說明 |
|---|---|---|---|
| #/components/parameters/RequestId | header | 選填 | — |
請求本體 (Request Body)
application/json{
"$ref": "#/components/schemas/HandoffExchangeRequest"
}回應代碼 (Responses)
呼叫範例 (cURL Sample)
curl -X POST "https://tsmc-thsr-api.liontravel.dev/session/exchange" \ -H "Api-Key: YOUR_API_KEY" \ -H "Authorization: Bearer YOUR_HANDOFF_JWT"
Send the same JSON shape the booking site already uses internally (`trip_type`, `segments`, `tickets`, `customer`, `total_price`). `total_price` must be computed on the booking backend before submit; this API does not recalculate fares. Required header `Idempotency-Key` (see parameter description for generation guidance). One unique key per logical order; reuse the same key when retrying the same payload after timeouts or `502`. Optional `Request-Id` for cross-system tracing; omit by default — the API still returns `request_id` on errors (server-generated when the header is absent).
請求參數 (Headers / Parameters)
| 參數名稱 | 位置 | 必要性 | 說明 |
|---|---|---|---|
| #/components/parameters/IdempotencyKey | header | 選填 | — |
| #/components/parameters/RequestId | header | 選填 | — |
請求本體 (Request Body)
application/json (必填){
"$ref": "#/components/schemas/CreateOrderRequest"
}回應代碼 (Responses)
呼叫範例 (cURL Sample)
curl -X POST "https://tsmc-thsr-api.liontravel.dev/orders" \ -H "Api-Key: YOUR_API_KEY" \ -H "Authorization: Bearer YOUR_BOOKING_ACCESS_TOKEN" \ -H "Idempotency-Key: idem_20261006_230954_a1b2c3d4" \ -H "Content-Type: application/json" \ -d @fixtures/sample-order.json
資料結構模型 (Schemas & Data Models)
Employee id from handoff JWT `sub`; must match `customer.emp_id` on orders.
Present when name/email were included in the handoff JWT.
{
"type": "string",
"enum": [
"oneway",
"round"
]
}Train row id from the booking site database (UUID).
Must match `session.subject` from exchange; usually pre-filled from handoff JWT `sub`.
Basic email shape (same rules as booking site form validation).
取票證件號碼(不分大小寫,系統轉大寫)。`id_type=national_id`:台灣身分證 `^[A-Z][12]\d{8}$` 且須通過檢查碼;`id_type=passport`:護照 / 居留證 6–20 碼英數。規則同 booking site `features/shared/idDocument.ts`。
取票證件類別:`national_id` = 身分證、`passport` = 居留證 / 護照。
取票場區(廠區編號,如 `F12P8`),選項來自 booking site `app_settings.pickup_locations`。
Order total in TWD (integer), computed by the booking site; not verified against segments on this API.
One segment for `oneway`, up to two for `round`.
Customer-facing order number assigned when ERP accepts the submit.
Trace id for this HTTP call (from `Request-Id` header when valid; otherwise server-generated).
