Skip Navigation

 

Stay Connected and Keep Current

 

Keeping you informed with the latest and greatest.

 

 

CSL 2

Content Services for Lodging Deep Dive Part 2: Getting Details


Ken Tabor | July 2019

Introducing this Sample Code

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

  • Room rates and availability supplied from multiple aggregator sources offering millions of property options
  • Property information including where it is, how to contact, and display-ready image links
  • Corporate discounts, loyalty identification, and international currency types

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 Get Hotel Details 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.

Requesting content is an important step in a typical hotel shop-and-book workflow. You’ll find that the sample app accompanying this article demonstrates how to call the Get Hotel Details API, parse the results, and display its contents. Our goal is providing developers a quick start 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

Get Hotel Details V1 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

The screenshot above shows the sample app is text-based and runs on the command-line. When it starts up it does the following:

  • Reads hotel search criteria from a config file
  • Authenticates to receive an API access token
  • Makes a request to Get Hotel Details API
  • Stores the response data
  • Parses through the response to display 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.

Ways you might experiment with the sample code include:

  • Running it a few times to observe its behavior
  • Reading through the code
  • 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 is used to “git clone” the source code. 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 are transferred across the network.

Getting Sabre Credentials

You will need your Sabre API CERT-environment credentials for this sample app to fully function. How are private credentials used in the sample app? As part of authentication to get a token that is used when calling the Get Hotel Details 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 Get Hotel Details 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 the O/S environment variable that you can create on your local development machine. Using an environment variable is suggested because that hides the real value.

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

Running the Sample App

Running the sample app after setup is easily done following these 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 important parts of the response returned from the API. This includes basic property information, and a list of nightly room rates from all of the content suppliers.

Sabre APIs Used

This sample app is meant to demonstrate how you might use lodging APIs in real-world use-cases. Two APIs are highlighted in this sample app: Get Hotel Details, and Authentication.

Get Hotel Details V1 API

The sample code associated with this article demonstrates setting up and making a request to the Get Hotel Details API. It also shows one way to parse through the response and display portions of it.

Read more about the hotel API on these Sabre-hosted documentation pages:

Authentication API

Most APIs are protected in some manner. For example, they require authentication, and that a valid token is sent up as part of the header for every request verifying 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 you want to get details about 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 = {

  hotelCode: '100148572',

  date: {

    checkIn: '2019-07-01',

    checkOut: '2019-07-05',

  },

};

You will find the hotelCode property is what drives the search. One way to get hotel codes is through the use of Get Hotel Availability V2. Consider reading the first blog article in this series to learn more.

Occasionally the search is prevented because the checkIn and checkOut dates are in the past.

Changing Supplier Sources

Changing the information supplier source means reading lodging data from any or all of a number of content aggregators. You will see how the API request is setup in the file named hotelDetailsModel.js in the requestPayload variable. Look at the table documented below to match up Aggregator ID numbers with the information aggregators.

When you read through the code you will see a request element named RateInfoRef.InfoSource. That is a comma-delimited string listing all of the supplier codes you want information from.

Responses from the API will contain consistent data structures no matter what the original content looks like from each source. This helps you compare data that looks similar in nature when presenting it to your app’s users.

Decoding the Rate Source

Getting access to our content partners unlocks your ability to read details about a hotel property from a collection of millions of options.

Look for the RateSource attribute in the API response data to determine precisely which source provided information such as room names and rates. Here is a table mapping ID-numbers to the names of content sources:

 

Value Provider
100 Sabre GDS
110 Expedia Partner Solutions
112 Bedsonline
113 Booking.com

Look for Rate Key in the Response

As you look through the API response you will recognize an attribute named RateKey repeated throughout. Seeing it multiple times may seem unusual, but in fact it is working as expected. You will find a RateKey value for each room rate plan returned by every content aggregator source.

Use it as a type of unique identifier in subsequent hotel-related API calls. A good real-world use-case is with Hotel Price Check V2.

Cached Response for Debugging

The sample app creates a file called cachedResponse.json every time it is run. The entire contents of the API response is saved as a convenient debugging facility for you. Read through the response to see all of the information returned.

Some of the response is displayed by the sample app. You will quickly realize that more data exists, and you might want to use it as part of your software application.

Next Steps

Leverage this sample app as a workbench. It is easily changed and ought to be an accelerator for your learning. Hopefully you find it easy to experiment with Get Hotel Details.

Look up the API docs and discover all that it can do:

Find something interesting in the docs? Try it out by modifying the sample app request attributes encoded in hotelDetailsModel.js. Makes changes and run the app to observe results of your experiment.

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