I'm trying the Amadeus python-sdk. When I call the flight offers price api:
amadeus.post('/v1/shopping/flight-offers/pricing', body)
I get this response:
{
"errors":[
{
"code":"38189",
"title":"Internal error",
"detail":"An internal error occurred, please contact your administrator",
"status":"500"
}
]
}
This is the body I used:
body = {'data': {'type': 'flight-offers-pricing', 'flightOffers': [{'type': 'flight-offer', 'id': '1', 'source': 'GDS', 'instantTicketingRequired': False, 'nonHomogeneous': False, 'oneWay': False, 'lastTicketingDate': '2020-03-01', 'numberOfBookableSeats': 4, 'itineraries': [{'duration': 'PT14H10M', 'segments': [{'departure': {'iataCode': 'GIG', 'at': '2020-03-01T23:30:00'}, 'arrival': {'iataCode': 'CMN', 'terminal': '2', 'at': '2020-03-02T12:10:00'}, 'carrierCode': 'AT', 'number': '212', 'aircraft': {'code': '788'}, 'operating': {'carrierCode': 'AT'}, 'id': '3', 'numberOfStops': 0, 'blacklistedInEU': False}, {'departure': {'iataCode': 'CMN', 'terminal': '2', 'at': '2020-03-02T15:45:00'}, 'arrival': {'iataCode': 'MAD', 'terminal': '4S', 'at': '2020-03-02T17:40:00'}, 'carrierCode': 'AT', 'number': '970', 'aircraft': {'code': '73G'}, 'operating': {'carrierCode': 'AT'}, 'id': '4', 'numberOfStops': 0, 'blacklistedInEU': False}]}, {'duration': 'PT31H20M', 'segments': [{'departure': {'iataCode': 'MAD', 'terminal': '4S', 'at': '2020-03-05T18:40:00'}, 'arrival': {'iataCode': 'CMN', 'terminal': '2', 'at': '2020-03-05T20:30:00'}, 'carrierCode': 'AT', 'number': '971', 'aircraft': {'code': '738'}, 'operating': {'carrierCode': 'AT'}, 'id': '47', 'numberOfStops': 0, 'blacklistedInEU': False}, {'departure': {'iataCode': 'CMN', 'terminal': '2', 'at': '2020-03-06T16:40:00'}, 'arrival': {'iataCode': 'GIG', 'at': '2020-03-06T22:00:00'}, 'carrierCode': 'AT', 'number': '213', 'aircraft': {'code': '788'}, 'operating': {'carrierCode': 'AT'}, 'id': '48', 'numberOfStops': 0, 'blacklistedInEU': False}]}], 'price': {'currency': 'USD', 'total': '2778.98', 'base': '2568.00', 'fees': [{'amount': '0.00', 'type': 'SUPPLIER'}, {'amount': '0.00', 'type': 'TICKETING'}]}, 'pricingOptions': {'fareType': ['PUBLISHED'], 'includedCheckedBagsOnly': True}, 'validatingAirlineCodes': ['AT'], 'travelerPricings': [{'travelerId': '1', 'fareOption': 'STANDARD', 'travelerType': 'ADULT', 'price': {'currency': 'USD', 'total': '1625.49', 'base': '1520.00'}, 'fareDetailsBySegment': [{'segmentId': '3', 'cabin': 'BUSINESS', 'fareBasis': 'DA0R0BRA', 'class': 'D', 'includedCheckedBags': {'quantity': 3}}, {'segmentId': '4', 'cabin': 'BUSINESS', 'fareBasis': 'DA0R0BRA', 'class': 'D', 'includedCheckedBags': {'quantity': 3}}, {'segmentId': '47', 'cabin': 'ECONOMY', 'fareBasis': 'XL0R0BRA', 'class': 'X', 'includedCheckedBags': {'quantity': 2}}, {'segmentId': '48', 'cabin': 'ECONOMY', 'fareBasis': 'XL0R0BRA', 'class': 'X', 'includedCheckedBags': {'quantity': 2}}]}, {'travelerId': '2', 'fareOption': 'STANDARD', 'travelerType': 'CHILD', 'price': {'currency': 'USD', 'total': '1153.49', 'base': '1048.00'}, 'fareDetailsBySegment': [{'segmentId': '3', 'cabin': 'BUSINESS', 'fareBasis': 'DA0R0BRACH', 'class': 'D'}, {'segmentId': '4', 'cabin': 'BUSINESS', 'fareBasis': 'DA0R0BRACH', 'class': 'D'}, {'segmentId': '47', 'cabin': 'ECONOMY', 'fareBasis': 'XL0R0BRACH', 'class': 'X'}, {'segmentId': '48', 'cabin': 'ECONOMY', 'fareBasis': 'XL0R0BRACH', 'class': 'X'}]}]}]}}
I tested the same request with postman and it worked. Any idea what could be causing this?
Thanks.
I was able to fix the problem. First, I checked the headers and body of the request:
amadeus.post('/v1/shopping/flight-offers/pricing', data)
Using this code
try:
pricing = amadeus.post('/v1/shopping/flight-offers/pricing', body)
print(pricing.result)
except ResponseError as error:
print('headers: ', error.response.request.headers)
print('body: ', error.response.request.params)
These are the headers I get:
{
'User-Agent': 'amadeus-python/3.1.0 python/3.6.8',
'Accept': 'application/json, application/vnd.amadeus+json',
'Authorization': 'Bearer ...'
}
While according to their postman collection the Content-Type header is required. I cloned the repo and added the Content-Type header to the post request and it worked fine.