雄獅旅遊

高鐵團票登記

預購系統/技術文件庫/B2E TSMC THSR Booking API
外部 API 規格•api-1.json
OpenAPI 3.0

B2E TSMC THSR Booking API

Session Exchange 換票 Token 與 Orders 訂單送交 ERP 之 Server-to-Server OpenAPI 規格書。

最後更新:2018/10/20•檔案規格:22 KB
Base Servers (伺服器端點)
https://tsmc-thsr-api.liontravel.devStage(測試機,.dev 網域)
驗證需求 (Authentication)
Api-Key每次呼叫均需帶入 Header Api-Key
Bearer Token/orders 需夾帶 exchange 取得之 booking_access_token

API 端點規範 (Endpoints)

POST/session/exchange
exchangeHandoffSession

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/RequestIdheader選填—

請求本體 (Request Body)

application/json
{
  "$ref": "#/components/schemas/HandoffExchangeRequest"
}

回應代碼 (Responses)

200OK
400
401HANDOFF_TOKEN_INVALID, HANDOFF_TOKEN_EXPIRED, HANDOFF_TOKEN_USED
500

呼叫範例 (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"
POST/orders
createOrder

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/IdempotencyKeyheader選填—
#/components/parameters/RequestIdheader選填—

請求本體 (Request Body)

application/json (必填)
{
  "$ref": "#/components/schemas/CreateOrderRequest"
}

回應代碼 (Responses)

201Order submitted to ERP (manual processing follows)
400
401
403
409
500
502

呼叫範例 (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)

HandoffExchangeRequesttype: object
handoff_tokenstring
SessionExchangeResponsetype: object
booking_access_tokenstring必填
token_typestring必填
expires_ininteger必填
sessionBookingSessionContext必填
BookingSessionContexttype: object
activity_idstring必填
subjectstring必填

Employee id from handoff JWT `sub`; must match `customer.emp_id` on orders.

prefillobject

Present when name/email were included in the handoff JWT.

TripTypetype: string
{
  "type": "string",
  "enum": [
    "oneway",
    "round"
  ]
}
Ticketstype: object
adultinteger必填
childinteger必填
seniorinteger必填
disabledinteger必填
Segmenttype: object
train_idstring必填

Train row id from the booking site database (UUID).

train_nostring必填
datestring必填
fromstring必填
tostring必填
depstring必填
arrstring必填
seatsinteger
Customertype: object
emp_idstring必填

Must match `session.subject` from exchange; usually pre-filled from handoff JWT `sub`.

namestring必填
phonestring必填
emailstring必填

Basic email shape (same rules as booking site form validation).

id_numberstring必填

取票證件號碼(不分大小寫,系統轉大寫)。`id_type=national_id`:台灣身分證 `^[A-Z][12]\d{8}$` 且須通過檢查碼;`id_type=passport`:護照 / 居留證 6–20 碼英數。規則同 booking site `features/shared/idDocument.ts`。

id_typestring

取票證件類別:`national_id` = 身分證、`passport` = 居留證 / 護照。

pickup_locationstring

取票場區(廠區編號,如 `F12P8`),選項來自 booking site `app_settings.pickup_locations`。

CreateOrderRequesttype: object
total_priceinteger必填

Order total in TWD (integer), computed by the booking site; not verified against segments on this API.

trip_typeTripType必填
segmentsarray必填

One segment for `oneway`, up to two for `round`.

ticketsTickets必填
customerCustomer必填
Ordertype: object
order_nostring必填

Customer-facing order number assigned when ERP accepts the submit.

total_priceinteger必填
trip_typeTripType必填
segmentsarray必填
ticketsTickets必填
customerCustomer必填
erp_referencestring
created_atstring必填
CreateOrderResponsetype: object
orderOrder必填
ErrorBodytype: object
codestring必填
messagestring必填
detailsobject
ErrorResponsetype: object
errorErrorBody必填
request_idstring必填

Trace id for this HTTP call (from `Request-Id` header when valid; otherwise server-generated).