Skip to content

Instantly share code, notes, and snippets.

@chhhris
Last active January 5, 2018 20:24
Show Gist options
  • Save chhhris/26ec72e136973279724b037a22345ddf to your computer and use it in GitHub Desktop.
Save chhhris/26ec72e136973279724b037a22345ddf to your computer and use it in GitHub Desktop.
Skyscanner flight price discrepancy
# ruby
params = {
  :country=>"US", 
  :currency=>"USD", 
  :locale=>"en-US", 
  :locationSchema=>"iata", 
  :apikey=>"ve518156965014636303894819187830", 
  :originplace=>"JFK-sky", 
  :adults=>1, 
  :children=>0, 
  :infants=>0, 
  :cabinclass=>"Economy", 
  :destinationplace=>"BGI", 
  :outbounddate=>"2018-02-15", 
  :inbounddate=>"2018-02-18"
}
url = "http://business.skyscanner.net/apiservices/pricing/v1.0/?apikey=ve518156965014636303894819187830"

POST to Skyscanner API

response = RestClient.post(url, params, { Accept: 'application/json' })
polling_url = response.headers[:location]

GET to Skyscanner API

response = RestClient.get("#{polling_url}?apiKey=#{Trip::FLIGHT_API_KEY}", { accept: :json })
cheapest_flight = JSON.parse(response)['Itineraries'].first
flight_price = cheapest_flight['PricingOptions'].first['Price']
booking_link = cheapest_flight['PricingOptions'].first['DeeplinkUrl']

cheapest_flight response

2.2.2 :074 > cheapest_flight = JSON.parse(response)['Itineraries'].first

=> {"OutboundLegId"=>"12712-1802152359--32171-0-9868-1802160532", "InboundLegId"=>"9868-1802181514--32171-0-12712-1802181935", "PricingOptions"=>[{"Agents"=>[2480144], "QuoteAgeInMinutes"=>478, "Price"=>283.51, "DeeplinkUrl"=>"http://partners.api.skyscanner.net/apiservices/deeplink/v2?_cje=l5a9YhdiSORpfQ4SVtD2QNzM9uMf8AymiAJCWfKC4bwJBUVlfJs5C1vgxHrHY%2fIt&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fUS%2fen-us%2fUSD%2ffdep%2f2%2f12712.9868.2018-02-15%2c9868.12712.2018-02-18%2fair%2ftrava%2fflights%3fitinerary%3dflight%7c-32171%7c1561%7c12712%7c2018-02-15T23%3a59%7c9868%7c2018-02-16T05%3a32%7c273%2cflight%7c-32171%7c662%7c9868%7c2018-02-18T15%3a14%7c12712%7c2018-02-18T19%3a35%7c321%26carriers%3d-32171%26operators%3d-32171%2c-32171%26passengers%3d1%26channel%3ddataapi%26cabin_class%3deconomy%26facilitated%3dfalse%26ticket_price%3d283.51%26is_npt%3dfalse%26is_multipart%3dfalse%26client_id%3dskyscanner_b2b%26request_id%3d17604f36-ba4e-47f8-a0d3-25b828e6edcc%26deeplink_ids%3deu-west-1.prod_745b33bd856e37a96f5c543a0e3fb8ea%26commercial_filters%3dfalse%26q_datetime_utc%3d2018-01-05T12%3a15%3a34"}, ... ], "BookingDetailsLink"=>{"Uri"=>"/apiservices/pricing/v1.0/3d04e5c30af3497aadd2d9581807907b_rrsqbjcb_06a13f0a788e803fcc56e78802891a26/booking", "Body"=>"OutboundLegId=12712-1802152359--32171-0-9868-1802160532&InboundLegId=9868-1802181514--32171-0-12712-1802181935", "Method"=>"PUT"}}

@chhhris
Copy link
Author

chhhris commented Jan 5, 2018

As you can see above, the first flight returned has a price of $283.51, however when you click the DeeplinkUrl it resolves to $960.51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment