Flight Offers API传travelClass=ECONOMY返回非经济舱结果是否正常
Amadeus Flight Offers API travelClass参数筛选问题
问题描述
根据Flight Offers API的GET接口文档,发起请求时可添加travelerClass作为筛选条件。传入travelerClass参数值为ECONOMY时,预期仅返回经济舱的航班报价,但实际返回结果的fareDetailsBySegment节点中,部分报价的cabin字段出现BUSINESS、PREMIUM_ECONOMY等非经济舱取值,需要确认该情况是否符合接口预期。
核心诉求
- 获取纯经济舱的可预订航班报价,确认接口返回的航班报价是否会严格受
travelerClass参数的筛选限制 - 若存在实现上述筛选需求的更优方案,希望同步告知
请求示例
Amadeus.shopping.flightOffersSearch.get({ originLocationCode: 'SYD', destinationLocationCode: 'BKK', departureDate: '2022-11-01', adults: '1', travelClass: 'ECONOMY' }).then(...)
异常返回示例
传入ECONOMY筛选参数后,返回包含BUSINESS舱位的报价样例如下:
{ "type": "flight-offer", "id": "22", "source": "GDS", "instantTicketingRequired": false, "nonHomogeneous": false, "oneWay": false, "lastTicketingDate": "2022-11-01", "numberOfBookableSeats": 6, "itineraries": [ { "duration": "PT28H20M", "segments": [ { "departure": { "iataCode": "SYD", "terminal": "1", "at": "2022-11-01T12:00:00" }, "arrival": { "iataCode": "PVG", "terminal": "2", "at": "2022-11-01T19:30:00" }, "carrierCode": "MU", "number": "562", "aircraft": { "code": "77W" }, "operating": { "carrierCode": "MU" }, "duration": "PT10H30M", "id": "13", "numberOfStops": 0, "blacklistedInEU": false }, { "departure": { "iataCode": "PVG", "terminal": "1", "at": "2022-11-02T08:45:00" }, "arrival": { "iataCode": "BKK", "at": "2022-11-02T12:20:00" }, "carrierCode": "MU", "number": "541", "aircraft": { "code": "320" }, "operating": { "carrierCode": "MU" }, "duration": "PT4H35M", "id": "14", "numberOfStops": 0, "blacklistedInEU": false } ] } ], "price": { "currency": "EUR", "total": "4048.84", "base": "3858.00", "fees": [ { "amount": "0.00", "type": "SUPPLIER" }, { "amount": "0.00", "type": "TICKETING" } ], "grandTotal": "4048.84" }, "pricingOptions": { "fareType": [ "PUBLISHED" ], "includedCheckedBagsOnly": true }, "validatingAirlineCodes": [ "MU" ], "travelerPricings": [ { "travelerId": "1", "fareOption": "STANDARD", "travelerType": "ADULT", "price": { "currency": "EUR", "total": "4048.84", "base": "3858.00" }, "fareDetailsBySegment": [ { "segmentId": "13", "cabin": "ECONOMY", "fareBasis": "YSE0WDNQ", "class": "Y", "includedCheckedBags": { "quantity": 2 } }, { "segmentId": "14", "cabin": "BUSINESS", "fareBasis": "QSE0WCNL", "class": "Q", "includedCheckedBags": { "quantity": 2 } } ] } ] }
解答
该现象符合接口现有设计逻辑。travelClass属于偏好类参数,而非强校验筛选参数:接口收到该参数后会优先返回对应舱位的报价,但不会强制过滤所有存在非目标舱位航段的结果。当联程航线存在目标舱位余票不足、航司放出混舱优惠票的情况时,就会返回部分航段为其他舱等的报价,和当前遇到的场景一致。
接口本身没有提供强校验全航段舱位的参数,要获取全航段均为经济舱的报价,只需在拿到接口返回结果后增加一层本地过滤:
- 遍历每个报价下
travelerPricings节点内所有fareDetailsBySegment条目 - 校验所有条目的
cabin字段是否全部等于ECONOMY - 剔除存在任意航段
cabin为非ECONOMY值的报价,剩余结果即为纯经济舱可预订报价
过滤判断时直接以接口返回的cabin字段值为准即可,不需要自行通过舱位代码(比如示例里的Q舱)做映射判断,该字段值已经是GDS和航司同步后的标准舱等标注。
内容的提问来源于stack exchange,提问作者Ahmad Qaasim
相关产品推荐
相关产品推荐

