以 NDJSON 流渐进接收匹配的火车行程。
认证和请求头
| 请求头 | 说明 |
|---|---|
Authorization | Bearer <secret_key>。密钥只能保存在服务器端,不能写入客户端日志。 |
X-Travelandz-Id | <public_key>:<profile_code>,持久化的 profile code 格式为 dp_<12 位字母数字>。 |
Accept | 渐进式 stream 响应使用 application/x-ndjson。 |
Content-Type | 带 JSON body 的请求使用 application/json。 |
请求
使用与 POST /v1/trains/journeys 相同的 JSON body。
请求体结构
originLocation id returned by
/locations.destinationLocation id returned by
/locations.datepassengerspassengers[]typeyouth = 0–27 years, adult = 28–59 years, senior = 60+ years.成功响应
响应类型为 application/x-ndjson。每个非错误行都是没有 wrapper 的完整行程对象。
响应体结构
gdsproviderjourneyIditineraryitinerary[]itineraryIndexitinerary[]segmentsitinerary[]segments[]segmentIditinerary[]segments[]departureitinerary[]segments[]departuredepartureAtitinerary[]segments[]departurenameitinerary[]segments[]departurelocationIditinerary[]segments[]departurecountryitinerary[]segments[]departurecountryCodeitinerary[]segments[]arrivalitinerary[]segments[]arrivalarrivalAtitinerary[]segments[]arrivalnameitinerary[]segments[]arrivallocationIditinerary[]segments[]arrivalcountryitinerary[]segments[]arrivalcountryCodeitinerary[]segments[]identifieritinerary[]segments[]transportitinerary[]segments[]durationInMinutesitinerary[]segments[]operatoritinerary[]segments[]operatorcodeitinerary[]segments[]operatornameitinerary[]segments[]operatorimageUrlitinerary[]segments[]serviceitinerary[]segments[]servicenameitinerary[]segments[]serviceimageUrlstopoversstopovers[]stopoverIndexstopovers[]durationInMinutesrouteroute[]itineraryIndexroute[]stopoverIndexcomfortClassescomfortClasses[]accommodationsaccommodations[]ticketClassesticketClasses[]comfortClassticketClasses[]serviceClass错误
400表示验证失败或存在未知字段。401或403表示 API 凭证无效。- 供应方失败时返回
500 internal_communication_error或unknown_error。 - 流错误行可能包含
error: true、code: zero_journeys_found和statusCode: 404。
使用说明
逐行读取响应,并对每行调用 JSON.parse。不要把流当作单个 JSON 文档解析。
cURL 示例
bash
curl --request POST \
--url "https://api.sandbox.travelandz.com/v1/trains/journeys/stream" \
--header "Authorization: Bearer $TRAVELANDZ_SECRET_KEY" \
--header "X-Travelandz-Id: $TRAVELANDZ_PUBLIC_KEY:$TRAVELANDZ_PROFILE_CODE" \
--header "Accept: application/x-ndjson" \
--data '{"origin":"originId","destination":"destinationId","date":"2026-08-20","passengers":[{"type":"adult"}]}'