How to get a session key from a Skyscanner API Submit request - Ruby

In my application, I want to get pricing information for the direct price of a flight. I used the SkyScanner API for this . I read the documentation before the resulting data I need to create a pricing service session. Which can be generated by the post api and then it provides SessionKey

with these SessionKey

and apiKey

, I can recover the data. So how can I get the Sessionkey as I figured it should be provided by the API server.

Here's my attempt:

require 'json'
require 'net/http'
require 'uri'


  post_params = { 
    :apiKey => "[API_KEY]",
    :country => "GB",
    :currency => "GBP",
    :locale => "en-GB",
    :adults =>1,
    :children => 0,
    :infants => 0,
    :originplace => '11235',
    :destinationplace => '13554',
    :outbounddate => '2015-05-19',
    :inbounddate => '2015-05-26',
    :locationschema => 'Default',
    :cabinclass => 'Economy',
    :groupPricing => true
  }


sessionkey_request = Net::HTTP.post_form(URI.parse('http://partners.api.skyscanner.net/apiservices/pricing/v1.0'), post_params )
get_data= "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/?apiKey=[API_KEY]"
puts sessionkey_request.inspect
temp = Net::HTTP.get_response(URI.parse(get_data)).body
# puts temp

      

In the console I get

<Net::HTTPCreated 201 Created readbody=true> # sessionkey_request.inspect

      

Don't get a SessionKey in response without it I can't get data. Please guide me where I am wrong. I am grateful for the solution.

For more details and real-time results Check API demo

Note. I have a check gem 'skyscanner' but that doesn't provide any method for Live Price. It provides methods to view the cache.

+3


source to share


1 answer


According to the document:

Successful response contains no content. The URL of the survey booking details are specified in the Location header of the response

try this:

sessionkey_request["location"]

      



I tested it on my system and it returns me:

http://partners.api.skyscanner.net/apiservices/pricing/v1.0/8e28260becd3441ca4e865396e224e7d_ecilpojl_EC71481935CEBB7EAF661BC24940D01D

      

The last part is yours sessionKey

, which you can use to query GET

. If you only want the last part (sessionKey), you can get it:

 > url = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/8e28260becd3441ca4e865396e224e7d_ecilpojl_EC71481935CEBB7EAF661BC24940D01D"
 > url.split('/').last
 => "8e28260becd3441ca4e865396e224e7d_ecilpojl_EC71481935CEBB7EAF661BC24940D01D" 

      

+3


source







All Articles