Customize your REST API response “auto-magically” with a Sabre or custom response view

by Leah Tucker

blog-rest_vs_soap

Thinking about putting your mobile travel application on a diet? REST API response getting a little thick around the middle?

We can help with that—because you’re now able to return a svelte, trimmed-down ReST API response “auto-magically” for all of your application requests using response views. A response view allows you to return final response content that has been pre-formatted to include or exclude certain response paths.

There are two types of response views: Sabre® response views and custom response views. A Sabre response view allows you to use pre-formatted, default Sabre® response views. Sabre did the heavy lifting and all the thinking for you. We figured out what to include and exclude for a given view. A custom response view means you have to do the thinking, but the result is pretty much life-changing. So there’s that. Custom response views allow you to define how the final response should be formatted, so you get to choose what stays/goes.

Pretty sure either option would be life-changing…so send us your reduced response size success stories (or your questions)!

Sabre response views

First option. There’s no requirement to using a Sabre® response view (other than being a current customer—and maybe already having an application with a response that you can format, of course.) These default views can be used by any Pseudo City Code (PCC).

Using a Sabre response view is easy. The main catch is that a given Sabre response view corresponds to a particular ReST API, which (right now) includes: Advanced Calendar Search, Alternate Airport Shop, Alternate Date, Bargain Finder Max, and InstaFlights Search. (We can be convinced, though, if you want us to create a response view for another ReST API. Or another Sabre (default) response view. Make a wish list and contact your Sabre representative.) Once you figure out which view you’d like to use, pass the view as a filter in the request URI to format the response. For example, view=BFM_ITIN_TOTAL_PRICE. That’s it.

For a list of the Sabre response views, and the excluded/included response paths for those views, check out the Response View API.

Example request and response

The following example demonstrates a request to return a response that is formatted using a Sabre default response view (BFM_ITIN_BASE_TAX_TOTAL_PRICE) for the Bargain Finder Max API.

Sample request

POST https://api.sabre.com/v1.9.5.1/shop/flights?mode=live&limit=1&enabletagging=true&view=BFM_ITIN_BASE_TAX_TOTAL_PRICE
{
  "OTA_AirLowFareSearchRQ": {
    "OriginDestinationInformation": [{
      "RPH": "1",
      "DepartureDateTime": "2016-08-21T00:00:00",
      "OriginLocation": {
        "LocationCode": "LAX"
      },
      "DestinationLocation": {
        "LocationCode": "JFK"
      }
    }],
    "TPA_Extensions": {
      "IntelliSellTransaction": {
        "RequestType": {
          "Name": "50ITINS"
        }
      }
    },
    "TravelerInfoSummary": {
      "AirTravelerAvail": [{
        "PassengerTypeQuantity": [{
          "Code": "ADT",
          "Quantity": 1
        }]
      }]
    },
    "TravelPreferences": {
      "TPA_Extensions": {

      }
    },
    "POS": {
      "Source": [{
        "RequestorID": {
          "Type": "0.AAA.X",
          "ID": "REQ.ID",
          "CompanyName": {
            "Code": "TN"
          }
        },
        "PseudoCityCode": "PCC"
      }]
    }
  }
}

Sample response

{
  "OTA_AirLowFareSearchRS": {
    "PricedItineraries": {
      "PricedItinerary": [{
        "SequenceNumber": 1,
        "AirItinerary": {
          "OriginDestinationOptions": {
            "OriginDestinationOption": [{
              "FlightSegment": [{
                "DepartureDateTime": "2016-08-21T06:00:00",
                "ArrivalDateTime": "2016-08-21T14:34:00",
                "StopQuantity": 0,
                "FlightNumber": "292",
                "DepartureAirport": {
                  "LocationCode": "LAX",
                  "content": ""
                },
                "ArrivalAirport": {
                  "LocationCode": "JFK",
                  "TerminalID": "8",
                  "content": ""
                },
                "MarketingAirline": {
                  "Code": "AA",
                  "content": ""
                }
              }]
            }]
          }
        },
        "AirItineraryPricingInfo": [{
          "FareReturned": true,
          "ItinTotalFare": {
            "BaseFare": {
              "Amount": 164.65,
              "CurrencyCode": "USD",
              "DecimalPlaces": 2
            },
            "FareConstruction": {
              "Amount": 164.65,
              "CurrencyCode": "USD",
              "DecimalPlaces": 2
            },
            "EquivFare": {
              "Amount": 164.65,
              "CurrencyCode": "USD",
              "DecimalPlaces": 2
            },
            "Taxes": {
              "Tax": [{
                "TaxCode": "TOTALTAX",
                "Amount": 26.45,
                "CurrencyCode": "USD",
                "DecimalPlaces": 2,
                "content": ""
              }]
            },
            "TotalFare": {
              "Amount": 191.1,
              "CurrencyCode": "USD",
              "DecimalPlaces": 2
            }
          }
        }]
      }]
    }
  },
  "RequestID": "BFM~7a7f805c-8c8b-4e3b-8524-da0bcc827743",
  "Page": {
    "Size": 1,
    "TotalTags": 50,
    "Offset": 1
  },
  "Links": [{
    "rel": "self",
    "href": "https://api.sabre.com/v1.9.5.1/shop/flights?mode=live&limit=1&enabletagging=true&view=BFM_ITIN_BASE_TAX_TOTAL_PRICE"
  }, {
    "rel": "linkTemplate",
    "href": "https://api.sabre.com/<version>/shop/flights?mode=<mode>"
  }, {
    "rel": "tagLookupLinkTemplate",
    "href": "https://api.sabre.com/<version>/shop/flights/tags/?mode="
  }, {
    "rel": "paginatedRequestLinkTemplate",
    "href": "https://api.sabre.com/<version>/shop/flights/<requestid>?mode=<mode>&limit=<limit>&offset=<offset>"
  }]
}

Wow, that is one svelte API response.

Custom response views

Second option. Looking to implement a few life-changing tweaks of your own? Custom response views allow you to define the individual data elements to be returned within a response payload. A custom response view is a view defined by a single Pseudo City Code (PCC). The only requirement (again, other than being a current customer, etc.) to using a custom response view is a little motivation and some ingenuity.

First, make a list of all your problems…as they relate to your current Sabre ReST API portfolio.

What if you could define the API response for your application? If you created a response view that trimmed the response to only include/exclude the paths that your application requires, you could be the envy of your development team for dreaming up the idea, forever and ever. (*long pause for dramatic effect*)

Using a custom response view is no sweat. First, you have to dream big about the response elements you’d like to include/exclude. Then come up with a name for your custom response view. To create it, define/associate the response paths to include/exclude using the Custom Response View API. And—note, like Sabre response views, custom response views can be used with the following APIs: Advanced Calendar Search, Alternate Airport Shop, Alternate Date, Bargain Finder Max, and InstaFlights Search. Then you just pass the view as a filter in the request URI to format the response. For example, view=BFM_SLOP.

Sample workflow

Here is a workflow that demonstrates how you could create a custom response view for the Bargain Finder Max API.

  1. Call the Create Custom Response View API to create a custom response view (BFM_SLOP) and include the Bargain Finder Max response paths you would like to include (or exclude):
    POST https://api.sabre.com/v1/lists/utilities/custom/views
    {
      "Name": "BFM_SLOP",
      "Includes": [
        "OTA_AirLowFareSearchRS.PricedItineraries.PricedItinerary.AlternateAirport",
        "OTA_AirLowFareSearchRS.PricedItineraries.PricedItinerary.SequenceNumber",
        "OTA_AirLowFareSearchRS.PricedItineraries.PricedItinerary.TicketingInfo"
      ]
    }
  2. Call the Bargain Finder Max API using your custom response view definition in the request URI:
    POST https://api.sabre.com/v1.9.5.1/shop/flights?mode=live&view=BFM_SLOP
            { "OTA_AirLowFareSearchRQ": {
            …See the Bargain Finder Max API for a sample request payload…
            } 
            }
  3. The Bargain Finder Max response will contain only the included BFM_SLOP elements:
    {
      "OTA_AirLowFareSearchRS": {
        "PricedItineraries": {
          "PricedItinerary": [{
            "SequenceNumber": 1,
            "AlternateAirport": true,
            "TicketingInfo": {
              "TicketType": "eTicket",
              "ValidInterline": "Yes"
            }
          }, {
            "SequenceNumber": 2,
            "TicketingInfo": {
              "TicketType": "eTicket",
              "ValidInterline": "Yes"
            }
          }]
        }
      }
    }
  4. Be sure to check out our documentation for more information on the Response View API and the Custom Response View API. Or if you would like to start exploring our REST APIs, send your requests for free by registering with API Explorer.

    Looking for other life-changing options for ReST? (Shout out!) Check out Alex Xavier’s article: Manage Large Volumes of Data: New REST Advanced Features.

    Don’t forget, now…

    Not ready for the coding burden of using or creating a response view? You can always request a compressed response for Advanced Calendar Search, Alternate Airport Shop, Alternate Date, Bargain Finder Max, and InstaFlights Search—by including “Accept-Encoding” in the request header.

    For example

    Accept-Encoding: gzip

    About Leah Tucker

    Leah Tucker is the Lead Technical Writer for Sabre REST APIs. Prior to technical writing, she worked in a number of roles, including front-end web development and UX, web and content standards, government/media relations and copyediting. Leah holds a BA in Communication and is also a part-time student where she takes various classes for fun, like chemistry.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>