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 区分:带 itemitineraryoffers_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 表示验证失败或存在未知字段。
  • 401403 表示 API 凭证无效。
  • 供应方失败时返回 500 internal_communication_errorunknown_error
  • 流错误对象包含 error: true、业务 codestatusCode

使用说明

使用 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"}]}'