How to Use the Booking.com API with Python

RapidAPI Team
The Era of APIs
Published in
5 min readDec 18, 2019

In the modern world, working with data is everything. The accessibility of data opens many doors for developers of various applications/services. Some services provide an interface to check whether the movie is good before going to the cinema. Others focus on business tasks like collecting, analyzing, processing and reusing data elsewhere. As demand for various data rises, so does the demand for APIs.

What is the Booking.com API?

We can divide the Booking API interface into three parts:

  1. Endpoints — Here we can get all available endpoints addresses as well as request type (GET, POST, etc.) and search for endpoints. Depending on which endpoint we choose, the content of the other two interface sections will change to represent the endpoint.
  2. Requests — On the top, we can see an endpoint description as well as choose a RapidAPI account. To the right, there is the button to get the results of the queried request. Please note that you have to subscribe to a billing plan to use this feature.
  3. Response — In this section, there are two tabs: Code Snippet & Test Result

Now let’s look at a concrete example.

How to use the Booking.com API

How to get access to the Booking.com API

  1. Sign up for a RapidAPI account — sign up using GitHub, Facebook, Google, or locally.
  2. On the next screen, you need to enter your name and your organization’s names. Consider making an organization account if you are planning to use RapidAPI with your team in the future. You can read more about this here.
  3. Subscribe to the Booking.com API — There are a few pricing options based on your usage. Hint: There’s a free plan that allows for 500 requests/month.
  4. Create your RapidAPI App — To use the endpoints we will need a RapidAPI Key, which will be provided within your user dashboard.

You can find your Application Key under ‘Security’:

Booking.com API Example

Let’s say we need to create a service that returns data about the hotels in the area. It’s worth noting that Booking API provides only GET endpoints. So, we can only collect data about hotels and then redirect the user to the desired hotel page. To collect data about hotels in the area, we can use ‘properties/list-by-map’ endpoint. Let us look at the required parameters:

In this example, we are looking for a one-room apartment for one guest. The check-in date is on the 15th of December, and check-out is on the 17th of December. Coordinates bounding box corresponds to the Philippine city Manila.

Now, let’s review the optional parameters:

Most of the parameters here are self-explanatory, except `search_id` and `categories_filter`.
`search_id` is for reusing what someone did earlier. We will not need it.
`categories_filter` is filtered by how many stars (from 0 to 5) you want your hotel to have. In our case, we are looking for 1–3 star hotels.

The result of this request is as follows:

There is a lot of data, but we are interested primarily in `result` which is the list of individual hotel data. Here is one of the hotel’s data:

See the data at   https://rapidapi.com/blog/booking-com-api-python/

We have a lot of useful data to use in our hotel service already, but some customers would like to have a look at the reviews. And there is an endpoint just for that — `properties/get-featured-reviews`. All we need to do is insert ‘hotel_id’ from the previous request.

Furthermore, that’s not all we can do with this API! We can get a list of facilities from the `properties/get-facilities`, a map from `properties/get-static-map`, and more.

We will get the following result:

Booking.com API Python Implementation

With the API key and endpoints figured out, we can implement a simple program to output hotel reviews to the user.

Related: How to use an API with Python

import requestslist_by_map_url = "https://apidojo-booking-v1.p.rapidapi.com/properties/list-by-map"list_by_map_querystring = {
"search_id":"none",
"children_age":"",
"price_filter_currencycode":"USD",
"languagecode":"en-us",
"travel_purpose":"leisure",
"categories_filter":"class%3A%3A1%2Cclass%3A%3A2%2Cclass%3A%3A3",
"children_qty":"",
"order_by":"popularity",
"guest_qty":"1",
"room_qty":"1",
"departure_date":"2019-12-19",
"bbox":"14.291283%2C14.948423%2C120.755688%2C121.136864",
"arrival_date":"2019-12-17"
}
see the rest at: https://rapidapi.com/blog/booking-com-api-python/

The result is a list of reviews for all the hotels in the area, which we can process separately.

Here’s how it looks for one hotel:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
RedDoorz Plus @ Kamuning Quezon City
b'Establishment exceeded my expectations. Clean and New.'
b'The establishment is clean, no water pressure issues, aircon working well. Safe area. Friendly and helpful staff. A nice cafe on the lobby.'
~~~~~~
b'Cool Place... '
b'The unit was GREAT!\nStaffs were courteous.\nThe furnitures was awesome...\nAffordable '
~~~~~~
b'Awesome! '
b'The unit was awesome\nThe receptionist was very accommodating\nThe price was very affordable\nLocation was great'
~~~~~~
b'Overall the hotel is very nice and comfortable to stay with.'
b'Super big room. With ref, TV, good bed, WIFI. Really a value for your money.'
~~~~~~
b'Awesome!!! '
b'The unit was GREAT!\nThe design and furnitures are awesome!\nThe value is AFFORDABLE!\nThe staffs were cool! '
~~~~~~
b'Just be careful when you make your reservations if payments are before or on arrival.'
b'The place was very good for the money, it was clean and comfortable.'
~~~~~~

Conclusion

The Booking API provides a convenient way for services to get information about hotels and similar places. In this tutorial, we learned how to use the RapidAPI interface to get started. We also illustrated what we need to do to use an API from RapidAPI. Then we broke down a practical example of Booking API usage: how to get data for the booking service. Finally, we implemented this example in Python.

Originally published at https://rapidapi.com on December 18, 2019.

--

--