Finding hotel ID on Booking.com via RapidAPI: What's the method?

I’m working with the RapidAPI interface for Booking.com and need assistance. Specifically, I want to obtain the reviews for a specific hotel, but I’m unsure of how to locate the hotel_id that’s necessary for this process. Can anyone guide me on finding this ID?

import requests

api_url = "https://booking-com.p.rapidapi.com/v1/hotels/reviews"

params = {
    "hotel_id": "1234567",
    "locale": "en-us",
    "sort_type": "SORT_HIGHEST_RATED",
    "customer_type": "individual,review_group_family",
    "language_filter": "en,es,it"
}

headers = {
    'x-rapidapi-host': "booking-com.p.rapidapi.com",
    'x-rapidapi-key': "your_api_key_here"
}

response = requests.get(api_url, headers=headers, params=params)

print(response.json())

To find the hotel_id for a specific hotel when using RapidAPI with Booking.com, you would typically use a search endpoint to retrieve hotel details and thereby extract the hotel_id. Here’s a step-by-step guide on how you can achieve this:

  1. Utilize the Hotel Search Endpoint:
    Use the search endpoint to look up hotels based on certain criteria like location, check-in/out dates, etc. This will return a list of hotels matching your search query, each with its hotel_id.

  2. Extract the Hotel ID:
    Parse the search results to find and extract the hotel_id of the hotel you’re interested in.

Here’s a conceptual example of how you could implement this using the response data from a typical hotel search endpoint:

import requests

api_url = "https://booking-com.p.rapidapi.com/v1/hotels/search"

params = {
    "locale": "en-us",
    "city_id": "-553173",
    "checkin_date": "2023-12-15",
    "checkout_date": "2023-12-16",
    "adults_number": 2
}

headers = {
    'x-rapidapi-host': "booking-com.p.rapidapi.com",
    'x-rapidapi-key': "your_api_key_here"
}

response = requests.get(api_url, headers=headers, params=params)
results = response.json()

# Assuming results['hotels'] contains hotel data
for hotel in results['hotels']:
    if hotel['hotel_name'] == "Your Desired Hotel Name":
        hotel_id = hotel['id']
        print(f"Found hotel_id: {hotel_id}")
        break
  1. Fetch Reviews Using Hotel ID:
    Now use this hotel_id in your reviews API call as you have already set up.

Keep in mind that the exact keys and structure of the response JSON may vary based on the API implementation from RapidAPI. Ensure you check the API documentation for the most accurate details about the endpoint and how data is structured. This approach allows you to dynamically find the hotel_id needed for further actions such as fetching reviews.

To efficiently obtain the hotel_id using the RapidAPI interface for Booking.com, follow these steps:

1. Use the Hotel Search Endpoint

First, initiate a search request using criteria such as city and dates:

import requests

api_url = "https://booking-com.p.rapidapi.com/v1/hotels/search"

params = {
    "locale": "en-us",
    "city_id": "-553173",  # Replace with actual city_id
    "checkin_date": "2023-12-15",
    "checkout_date": "2023-12-16",
    "adults_number": 2
}

headers = {
    'x-rapidapi-host': "booking-com.p.rapidapi.com",
    'x-rapidapi-key': "your_api_key_here"
}

response = requests.get(api_url, headers=headers, params=params)
results = response.json()

2. Extract the hotel_id

Iterate through the search results to find the desired hotel:

# Assuming results['hotels'] contains hotel data
for hotel in results['hotels']:
    if hotel['hotel_name'] == "Your Desired Hotel Name":
        hotel_id = hotel['id']
        print(f"Found hotel_id: {hotel_id}")
        break

3. Retrieve Reviews with hotel_id

Use the extracted hotel_id in your reviews request as shown in your initial setup.

Make sure to refer to RapidAPI's documentation for any slight variations in the API's response structure. This method guarantees you locate and use the correct hotel_id efficiently.