Content Services for Lodging Deep Dive Part 3: Checking Prices

by Ken Tabor

Introducing this Sample Code

We offer an API called Hotel Price Check V2 to help you find information about a specific property that meets your travelers’ needs. Through using the API, in one request, your application receives:

  • Confirmation that a room price returned during shopping activities is still applicable
  • Pricing details in a chosen currency format that are the latest supplied from our content aggregator
  • Mandatory information used to book a property

The goal is empowering you to build solutions that will help your travelers find their dream offers.

More Power, Less Programming

An “orchestrated service” like Hotel Price Check V2 is designed to make the developer experience easier. It bundles together several granular actions to supply a collection of data to an app for its user workflow. More information may be requested through orchestration with less code written. This helps make app code easier to reason about and improves its maintainability.

Price confirmation is a mandatory step in a typical hotel shop-and-book workflow. You will find that the sample app accompanying this article demonstrates how to call the Hotel Price Check API, parse the results, and display some of its contents. Our goal is supplying developers a quick start resource for using the API.

You will find this article provides additional context and extra resources to help you understand. Source code for the sample app is stored in a repo on our GitHub account. If you do not know about GitHub, it is a popular hosting provider for storing code using the git revision control system. Accessing our source code is free and easy.

SOAP and REST, Orchestrated and Granular

Hotel Price Check V2 supports two API design patterns: SOAP/XML and REST/JSON. Although this article concentrates on the REST edition of the API as a matter of focus, you will find the SOAP edition of the API matches its capabilities and features.

This API bundles together several actions at once. We offer a set of granular APIs if those better match your needs. Please refer to the documentation to learn more about them.

How it Works

You will see from the screenshot above that the sample app is command-line driven and text-based. It does these steps to run:

  • Reads rate key search criteria from a config file
  • Authenticates to receive an API access token
  • Makes a request to Hotel Price Check V2 API
  • Stores the response data
  • Parses through the response and displays parts of it

Delivering a text-based sample app like this is meant to simplify the learning for an audience of software developers. You will find the sample app’s source code on GitHub.

Experimenting with the sample code might include:

  • Running it a few times to observe its behavior
  • Reading through the source
  • Changing the search criteria file
  • Modifying options in the request model to get different data
  • Altering the response view to show other information

Consider this sample source code to be you “digital workbench” for discovering how to use the API. It should make integrating with your codebase quicker.

Setting-up the Sample App

Sample app setup involves performing a few, one-time-only, pre-requisite steps listed below.

Cloning with Git

Browse our code repo on Github to pull down a copy of it to your local machine. Look on the web page for the green button telling “Clone or download”.

The button reveals a URL when you click it. That URL is used to “git clone” the source. Cloning is how you first copy down a repo from the server to your personal machine using git.

Installing Project Dependencies

Notice that the sample app is written in JavaScript using NodeJS. That means you will need to have its run-time installed on your local development computer to run it.

After pulling down a copy of the sample app code repo, and installing NodeJS, you will need to install the open-source libraries that the sample app depends on. Do that by running this command in your local copy of the source code:

npm install

This tells npm (NodeJS Package Manager) to pull down copies of the open-source libraries the sample app includes. The process may take a few minutes as files transfer across the network.

Getting Sabre Credentials

You will need your Sabre API CERT-environment credentials for this sample app to fully function. Private credentials are used by the sample app as part of authentication to get a token. The token is used as a part of sending a request to the Hotel Check Price API.

Encoding Credentials

Using the APIs requires entering a secret and the app must be able to find it during the initial authentication process. Part of its logic is exchanging the secret for a token in order to properly call the Hotel Price Check API. Tokens are gained in part from using the private secret.

Simply open up the app’s source code and look at the file named config.js to find where the secret is declared. There is one attribute called userSecret where you can hard-code the string.

const APIConfig = {

  userSecret: process.env.SWS_API_SECRET || '',

};

userSecret is a base64-encoded string computed from steps you can read about.

Alternatively, the secret value may be picked-up from an O/S environment variable named SWS_API_SECRET that you can create on your development machine. Using the environment is a good practice because it hides the actual value from source code.

Keeping secrets and credentials out of revision control is a modern-day technique for practicing good “security hygiene”.

Running the Sample App

Run the sample app after setting up. Simply follow these three steps:

  • Open your command-line prompt
  • Navigate to where you have stored your local copy of the source code
  • Enter this command: npm start

You will see the app displays portions of the returned API response. You should see: the total price, nightly room rates, and commission numbers. NOTE: there is more information to be found in the complete service response.

Sabre APIs Used

The sample app demonstrates how you might use lodging APIs to satisfy real-world needs. Two APIs are used in this case: Authentication and Hotel Price Check.

Hotel Price Check V2 API

When you read through the sample code you will learn how it sets up and makes a request to the Hotel Price Check V2 API. The sample app parses through the response and displays parts of it.

More can be found in this Sabre-hosted documentation regarding the hotel APIs:

Authentication API

Most APIs are protected in some manner. For example, they require that a token is sent up for every request to verify its sender. Sabre REST APIs have this feature.

The sample app demonstrates how to call the Authentication API with private account information userSecret to receive an access token in reply. The token is sent along subsequent REST API calls as a header authorization Barer to prove the request is valid.

Read more about the authentication process on this Sabre-hosted page: How to get a token.

Updating the Search Criteria Config File

Switching the hotel price you want to check on is simple. Navigate to the app’s source code and look for the file searchCriteria.js to locate information used in the API request.

const SearchCriteria = {

  rateKey: 'fDLUGXAMH...ZXvTCO8OcFfSvO'

};

Only one piece of information is sent up to the API request. It is the rateKey. One way to get property rate keys is by using Get Hotel Availability V2. Learn more on that by reviewing the first blog article in this series and the second article in this series.

Look for Booking Key in the Response

Look through the API response for an attribute called BookingKey. This unique identifier is mandatory for booking the property.

There are three ways to book a property:

Choose one or more that best fits your software application and user needs.

Cached Response for Debugging

When the sample app runs it saves out the API response to a debug file called cachedResponse.json. It is not a crucial resource, but you may find it useful for debugging and development purposes.

Next Steps

Leverage this sample app as a workbench to more quickly learn the Hotel Price Check V2 API. Discover more about it by referencing these online docs:

Update the request attributes in hotelPricingModel.js when you find something in the API docs that you want to try. Make a change, run the app, and observe your experiment’s results.

You can get in touch with us through GitHub repo-level issues, and by submitting pull requests.

About Ken Tabor

Ken Tabor is a veteran programmer with years of experience developing websites, mobile apps, and video games. He shares his enthusiasm for technology as a writer, teacher, and frequent speaker at conferences including BigDesign, South by Southwest, and DevNexus. He is the author of, Responsive Web Design Toolkit, published by Focal Press. Areas of interest include JavaScript, augmented reality, developer experience, machine learning, and design thinking. Ken is currently a software architect at Sabre helping foster a modern developer experience for its future API platform. Feel free to reach out to Ken on Twitter @KenTabor