Getting a 500 Internal Server Error when Booking a Hotel with Amadeus API

96 views Asked by At

I'm working on integrating the Amadeus API into my application to allow users to book hotels. However, I'm encountering a 500 Internal Server Error when attempting to book a hotel using the provided offer ID.

Here's a simplified version of my Python code:

@app.post("/book_hotel")
async def book_hotel(
    offer_id: str = Query(..., description="Offer ID")
):
    try:
        # Confirm availability of a given offer
        offer_availability = amadeus.shopping.hotel_offer_search(offer_id).get()
        if offer_availability.status_code == 200:
            guests = [
                {
                    'id': 1,
                    'name': {'title': 'MR', 'firstName': 'BOB', 'lastName': 'SMITH'},
                    'contact': {'phone': '+33679278416', 'email': '[email protected]'}
                }
            ]

            payments = {
                'id': 1,
                'method': 'creditCard',
                'card': {
                    'vendorCode': 'VI',
                    'cardNumber': '4151289722471370',
                    'expiryDate': '2023-08'
                }
            }

            booking = amadeus.booking.hotel_bookings.post(offer_id, guests, payments).data
        else:
            return {"response": 'The room is not available'}
    except ResponseError as error:
        raise HTTPException(status_code=500, detail=str(error.response.body))

    return {
        "id": booking[0]['id'],
        "providerConfirmationId": booking[0]['providerConfirmationId']
    }

I'm providing a valid offer ID, '8ANZ20L7F2', but I'm consistently getting a 500 error. I've checked my API credentials, and they seem to be correct.

What could be causing this 500 Internal Server Error when trying to book a hotel with the Amadeus API? Are there any common issues or troubleshooting steps I should consider?

The other endpoints for fetching data and so work as expected, only this is the problem!

Any help or insights would be greatly appreciated. Thank you!

1

There are 1 answers

0
anna_ts On

There are a few reasons why you receive 500:

  • When it comes to booking a hotel in the test environment, your request is being sent to each hotel provider and each of them has a different environment and rules. There might be some connectivity issues with the providers that can lead to a timeout or even if many requests are sent towards a hotel they could block them.

  • Did you make sure the hotel you tried to book had the right payment policy? The current version of the Hotel Booking API only supports credit card payments. The Hotel Search API returns the payment policy of each hotel under acceptedPayments in the policies section.

  • Also, the credit card has already expired in the past.