POST/v1/trains/journeys/:gdsprovider/:journeyId/offers/stream

流式获取行程报价

渐进接收行程报价、完成状态和取消政策分块。

分享

渐进接收行程报价、完成状态和取消政策分块。

认证和请求头

请求头说明
AuthorizationBearer <secret_key>。密钥只能保存在服务器端,不能写入客户端日志。
X-Travelandz-Id<public_key>:<profile_code>,持久化的 profile code 格式为 dp_<12 位字母数字>。
Accept渐进式 stream 响应使用 application/x-ndjson。
Content-Type带 JSON body 的请求使用 application/json。

请求

使用与非流式行程报价端点相同的 path、query 和 JSON body。

请求参数结构

gdsprovider
enum
0
是
Currently 0
journeyId
string是
Journey id returned by the journey search.

请求查询参数模式

language
enum
eneszh
否
returnCancellationPolicies
boolean否

请求体结构

passengers
array是
passengers[]type
enum
youthadultsenior
是

成功响应

每个 NDJSON 行通过 type 区分:带 item 的 itinerary、offers_search_completed 或带 item 数组的 cancellation_policies。

响应体结构 (type=itinerary)

type
enum
itinerary
是
item
object是
itemitineraryIndex
number是
itemsegments
array是
itemsegments[]segmentId
string是
itemsegments[]departure
object是
itemsegments[]departuredepartureAt
string
格式: ISO 8601
是
itemsegments[]departurename
string是
itemsegments[]departurelocationId
string是
itemsegments[]departurecountry
string是
itemsegments[]departurecountryCode
string是
itemsegments[]arrival
object是
itemsegments[]arrivalarrivalAt
string
格式: ISO 8601
是
itemsegments[]arrivalname
string是
itemsegments[]arrivallocationId
string是
itemsegments[]arrivalcountry
string是
itemsegments[]arrivalcountryCode
string是
itemsegments[]identifier
string是
itemsegments[]transport
enum
trainbusferry
是
itemsegments[]durationInMinutes
number是
itemsegments[]operator
object是
itemsegments[]operatorcode
string是
itemsegments[]operatorname
string是
itemsegments[]operatorimageUrl
string可为空
itemsegments[]service
object是
itemsegments[]servicename
string可为空
itemsegments[]serviceimageUrl
string可为空
itemoffers
array是
itemoffers[]offerId
string是
itemoffers[]parts
array是
itemoffers[]parts[]segments
array是
itemoffers[]parts[]segments[]segmentId
string是
itemoffers[]parts[]segments[]amenities
array是
itemoffers[]parts[]segments[]amenities[]
string[]是
itemoffers[]parts[]flexibility
enum
non_flexsemi_flexfull_flex
是
itemoffers[]parts[]comfortClass
enum
basicstandardhighbestunknown
是
itemoffers[]parts[]serviceClass
enum
basicstandardhighbestunknown
是
itemoffers[]parts[]conditions
array是
itemoffers[]parts[]conditions[]type
string是
itemoffers[]parts[]conditions[]condition
string是
itemoffers[]parts[]conditions[]note
string否
itemoffers[]parts[]conditions[]conditionKey
string是
itemoffers[]parts[]cancellationPolicies
array是
itemoffers[]parts[]cancellationPolicies[]__typename
object是
itemoffers[]parts[]cancellationPolicies[]__typenametype
enum
CancellationByPercentageCancellationByPercentChargeCancellationByFixedChargeFullCancellableNonCancellable
是
itemoffers[]parts[]cancellationPolicies[]description
string否
itemoffers[]parts[]cancellationPolicies[]minimum_minutes_before_departure
number否
itemoffers[]parts[]cancellationPolicies[]maximum_minutes_before_departure
number否
itemoffers[]parts[]cancellationPolicies[]minimum_minutes_after_departure
number否
itemoffers[]parts[]cancellationPolicies[]maximum_minutes_after_departure
number否
itemoffers[]parts[]cancellationPolicies[]percentage
number否
When __typename is CancellationByPercentage
itemoffers[]parts[]cancellationPolicies[]chargePercentage
number否
When __typename is CancellationByPercentCharge
itemoffers[]parts[]cancellationPolicies[]chargeAmount
number否
When __typename is CancellationByFixedCharge
itemoffers[]parts[]cancellationPolicies[]currency
string
格式: ISO 4217 code
否
When __typename is CancellationByFixedCharge
itemoffers[]parts[]cancellationPolicies[]perPerson
boolean否
When __typename is CancellationByPercentCharge or CancellationByFixedCharge. Is optional
itemoffers[]parts[]cancellationPolicies[]perLeg
boolean否
When __typename is CancellationByPercentCharge or CancellationByFixedCharge. Is optional
itemoffers[]parts[]isRefundable
boolean是
itemoffers[]price
object是
itemoffers[]priceamount
number是
itemoffers[]pricecurrency
string是
itemoffers[]createdAt
string
格式: ISO 8601
是
itemoffers[]expiresAt
string
格式: ISO 8601
是

,

响应体结构 (type=offers_search_completed)

type
enum
offers_search_completed
是

,

响应体结构 (type=cancellation_policies)

type
enum
cancellation_policies
是
item
array是
item[]conditionKey
string是
item[]policies
array是
item[]policies[]__typename
object是
item[]policies[]__typenametype
enum
CancellationByPercentageCancellationByPercentChargeCancellationByFixedChargeFullCancellableNonCancellable
是
item[]policies[]description
string否
item[]policies[]minimum_minutes_before_departure
number否
item[]policies[]maximum_minutes_before_departure
number否
item[]policies[]minimum_minutes_after_departure
number否
item[]policies[]maximum_minutes_after_departure
number否
item[]policies[]percentage
number否
When __typename is CancellationByPercentage
item[]policies[]chargePercentage
number否
When __typename is CancellationByPercentCharge
item[]policies[]chargeAmount
number否
When __typename is CancellationByFixedCharge
item[]policies[]currency
string
格式: ISO 4217 code
否
When __typename is CancellationByFixedCharge
item[]policies[]perPerson
boolean否
When __typename is CancellationByPercentCharge or CancellationByFixedCharge. Is optional
item[]policies[]perLeg
boolean否
When __typename is CancellationByPercentCharge or CancellationByFixedCharge. Is optional

,

响应体结构 (error=true)

error
boolean是
code
string是
statusCode
number是

错误

  • 400 表示验证失败或存在未知字段。
  • 401 或 403 表示 API 凭证无效。
  • 供应方失败时返回 500 internal_communication_error 或 unknown_error。
  • 流错误对象包含 error: true、业务 code 和 statusCode。

使用说明

使用 type 作为区分字段;并非每行都是行程结构。读取到 offers_search_completed,并单独保存政策分块。

cURL 示例

bash
bash
curl --request POST \
  --url "https://api.sandbox.travelandz.com/v1/trains/journeys/0/journey_123/offers/stream?language=en&returnCancellationPolicies=true" \
  --header "Authorization: Bearer $TRAVELANDZ_SECRET_KEY" \
  --header "X-Travelandz-Id: $TRAVELANDZ_PUBLIC_KEY:$TRAVELANDZ_PROFILE_CODE" \
  --header "Accept: application/x-ndjson" \
  --data '{"passengers":[{"type":"adult"}]}'