Get Hotel Avail v2

node v12.2.0
version: 1.1.0
endpointsharetweet
This sample app shows how to call the Get Hotel Availability V2 API. This is an orchestrated service that returns rich content for properties including amenities, media, and lead-rates across mulitple content sources. For more information refer to this Sabre-hosted, online document: https://beta.developer.sabre.com/docs/travel-agency/content-services-for-lodging
First, bring in a helper-library called axios that makes API request code cleaner and easier. Your API token is brought in from a system environment variable. Use the token provided to you by the workshop coordinator. The one-time only setup step is adding the key-value pair here: https://runkit.com/settings/environment
const axios = require('axios'); const mytoken = process.env.TOKEN; const myAppId = process.env.APPID;
Use the airportCode and checkIn and CheckOut attributes in the following data structure to change where hotel properties are found in the API request. Change the searchCriteria values and run the sample app to see how your experiment causes different responses.
const searchCriteria = { location: { airportCode: 'LAS', stateCode: 'NV', countryCode: 'US', }, date: { checkIn: '2019-09-01', checkOut: '2019-09-05', }, };
This data structure sets up the request data and search parameters. Take note of how it uses the previously created `searchCriteria` data stucture to fill in several important attributes. InfoSource is an powerful attribute to review because it stipulates which aggregators returns content.
const requestPayload = { GetHotelAvailRQ: { SearchCriteria: { OffSet: 1, SortBy: 'SabreRating', SortOrder: 'DESC', PageSize: 100, AvailRatesOnly: true, GeoSearch: { GeoRef: { Radius: 50, UOM: 'MI', RefPoint: { Value: searchCriteria.location.airportCode, ValueContext: 'CODE', RefPointType: '6', StateProv: searchCriteria.location.stateCode, CountryCode: searchCriteria.location.countryCode, }, }, }, RateInfoRef: { ConvertedRateInfoOnly: false, CurrencyCode: 'USD', BestOnly: '2', PrepaidQualifier: 'IncludePrepaid', StayDateRange: { StartDate: searchCriteria.date.checkIn, EndDate: searchCriteria.date.checkOut, }, Rooms: { Room: [ { Index: 1, Adults: 2, }, ], }, InfoSource: '100,110,112,113', }, HotelPref: { AmenityCodes: { Inclusive: true, AmenityCode: [ '15', ], }, SabreRating: { Min: '3', Max: '5', }, }, ImageRef: { Type: 'MEDIUM', LanguageCode: 'EN', }, }, } };
Make the API request and display parts of it when successful. Notice that it dumps the entire API response for convenient debugging during development. Open it up and inspect all the various lodging information that comes back.
axios({ method: 'post', url: 'https://api-crt.cert.havail.sabre.com/v2.0.0/get/hotelavail', data: JSON.stringify(requestPayload), headers: { 'content-type': 'application/json', accept: 'application/json', authorization: `Bearer ${mytoken}`, 'Application-ID': myAppId } }) .then(function (response) { // HTTP 200 console.log(response.data); DisplayNames(response.data); }) .catch(function (error) { // HTTP 400 or 500 console.log('Something went wrong'); console.log(`${error.response.status} ... ${error.response.statusText}`); console.log(error.response.data); });
The most intresting part of the DisplayNames function is seeing how it loops through the collection of Hotel Availability Information to display the property name. This is an example to get you started processing the data.
function DisplayNames(data) { const hotelInfo = data.GetHotelAvailRS.HotelAvailInfos.HotelAvailInfo; hotelInfo.forEach((hotel) => { console.log(`${hotel.HotelInfo.HotelName}`); }); }
Loading…

no comments

    sign in to comment