Passing multiple parameters to hotel offers search in Amadeus python SDK

161 Views Asked by At

I am trying to pass multiple parameters to hotel offers using the Amadeus Python SDK but I am getting a 400 error code. How can I include checkInDate and checkOutDate in the request? here's the code :

  amadeus = Client(
            client_id = clientID,
            client_secret = ClientSecret
        )

        try:
            
            hotels_by_city = amadeus.shopping.hotel_offers.get(cityCode=citycode,checkInDate=checkindate,checkOutDate=checkoutdate,adults=adults,roomQuantity=rooms)
            k = hotels_by_city.data
            print(k)


                
1

There are 1 best solutions below

0
On

Here an example of how to use the Python SDK to implement Hotel Search and Book:

# Install the Python library from https://pypi.org/project/amadeus
from amadeus import Client, ResponseError

amadeus = Client(
client_id='YOUR_AMADEUS_API_KEY',
client_secret='YOUR_AMADEUS_API_SECRET'
)

try:
   # Get list of Hotels by city code
   hotels_by_city = amadeus.shopping.hotel_offers.get(cityCode='PAR', checkInDate='2021-01-10', checkOutDate='2021-01-12')

   # Get list of offers for a specific hotel
   hotel_offers = amadeus.shopping.hotel_offers_by_hotel.get(hotelId = 'HSMADAMI', checkInDate='2021-01-10', checkOutDate='2021-01-12')

   # Confirm the availability of a specific offer
   offer = hotel_offers.data['offers'][0]['id']
   offer_availability = amadeus.shopping.hotel_offer(offer).get()

   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': '2021-08' } }

   hotel_booking = amadeus.booking.hotel_bookings.post(offer, guests, payments)
   print(hotel_booking.data)
except ResponseError as error:
   raise error