phpapicurlskyscanner

Skyscanner API for all hotel locations using CURL


I am trying to fetch geo catalogue data from skyscanner api. I have read documentation http://business.skyscanner.net/portal/en-GB/Documentation/ApiOverview

I have created api key. I am hitting api successfully and getting result same as on the http://business.skyscanner.net/portal/en-GB/Documentation/HotelsLivePricingQuickStart

I am hitting:-

http://partners.api.skyscanner.net/apiservices/hotels/autosuggest/v2/UK/GBP/en-GB/.$cityname.?apikey=prtl6749387986743898559646983194"

I want to get responce in JSON. Is it possible??

I have successfully get flight live prices here is link [Get error in using skyscanner Api of flight pricing in php using POST method.


Solution

  • <?php
    $checkin_date = "2017-05-05";
    $checkout_date = "2017-05-08";
    $guests = 10;
    $rooms=  4;
    $country_iso_code = "UK";
    $country_currency = "EUR";
    $locale_lang = "en-GB";
    $url = "http://partners.api.skyscanner.net/apiservices/hotels/liveprices/v2/$country_iso_code/$country_currency/$locale_lang/27539733/$checkin_date/$checkout_date/$guests/$rooms?apiKey=prtl6749387986743898559646983194";
    
    $ch = curl_init();
    $http_header = ["Content_type : application/json"];
    $options = [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTPHEADER => $http_header
    ];
    curl_setopt_array($ch, $options);
    $response = curl_exec($ch);
    curl_close($ch);
    
    var_dump($response);
    

    //Response in Json

    This is just basic code how you hit the api of skyscanner to get the data in json format using curl