Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Flights: Live Pricing

Burak Özdemir edited this page Oct 21, 2018 · 13 revisions

With the minimal setup, the Live Pricing Service can be used like below where it will return the flights from London Heathrow Airport to Istanbul Atatürk Airport which will take place on July 1st, 2017 where it will also exclude the flights which are not direct with the prices for one adult.

use OzdemirBurak\SkyScanner\Travel\Flights\LivePricing;

$pricing = new LivePricing($apiKey = 'your-api-key', $country = 'GB', $currency = 'GBP', $locale = 'en-GB');
$pricing->setParameters([
    'adults' => 1,
    'destinationPlace' => 'IST',
    'originPlace' => 'LHR',
    'outboundDate' => '2017-07-01',
    'stops' => 0
]);
$flights = $pricing->getFlights($onlyCheapestAgentPerItinerary = true);

After calling the getFlights() method, some part of the data that is returned will look like below where it will only return the agent with the lowest price.

0 => array:3 [
  "BookingDetailsLink" => {#33
    +"Uri": "/apiservices/pricing/v1.0/7d3120c1782f413db0b0947a11b103b6_rrsqbjcb_06a13f0a788e803fcc56e78802891a26/booking"
    +"Body": "OutboundLegId=13554-1707011405--31734-0-12585-1707012005&InboundLegId="
    +"Method": "PUT"
  }
  "OutboundLeg" => {#184
    +"Id": "13554-1707011405--31734-0-12585-1707012005"
    +"SegmentIds": array:1 [
      0 => 4
    ]
    +"OriginStation": 13554
    +"DestinationStation": 12585
    +"Departure": "2017-07-01T14:05:00"
    +"Arrival": "2017-07-01T20:05:00"
    +"Duration": 240
    +"JourneyMode": "Flight"
    +"Stops": []
    +"Carriers": array:1 [
      0 => 1755
    ]
    +"OperatingCarriers": array:1 [
      0 => 1755
    ]
    +"Directionality": "Outbound"
    +"FlightNumbers": array:1 [
      0 => {#185
        +"FlightNumber": "1990"
        +"CarrierId": 1755
        +"FlightCode": "TK1990"
        +"Carrier": {#203
          +"Id": 1755
          +"Code": "TK"
          +"Name": "Turkish Airlines"
          +"ImageUrl": "http://s1.apideeplink.com/images/airlines/TK.png"
          +"DisplayCode": "TK"
        }
      }
    ]
  }
  "Agent" => {#285
    +"QuoteAgeInMinutes": 14
    +"Price": 150.15
    +"DeeplinkUrl": "http://partners.api.skyscanner.net/apiservices/deeplink/v2?_cje=9bZBn9EG0XSSEDgJNqeSWejplS3SzHmr47vT4j4hddBllsVfNfz8iyqb3QfbWSFX&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fUK%2fen-gb%2fGBP%2fomeg%2f1%2f13554.12585.2017-07-01%2fair%2ftrava%2fflights%3fitinerary%3dflight%7c-31734%7c1990%7c13554%7c2017-07-01T14%3a05%7c12585%7c2017-07-01T20%3a05%26carriers%3d-31734%26passengers%3d1%26channel%3ddataapi%26cabin_class%3deconomy%26facilitated%3dfalse%26ticket_price%3d150.15%26is_npt%3dfalse%26is_multipart%3dfalse%26client_id%3dskyscanner_b2b%26request_id%3d69b73424-219c-4875-8364-d372df31e891%26deeplink_ids%3deu-west-1.prod_b082cca74550aa36be3a5a44c483c000%26commercial_filters%3dfalse%26q_datetime_utc%3d2017-05-26T06%3a55%3a48"
    +"Id": 3496199
    +"Name": "omegaflightstore.com"
    +"ImageUrl": "http://s1.apideeplink.com/images/websites/omeg.png"
    +"Status": "UpdatesComplete"
    +"OptimisedForMobile": false
    +"Type": "TravelAgent"
  }
]

If you pass the $onlyFirstAgentPerItinerary as false to the flight parser as getFlights($onlyFirstAgentPerItinerary = false), then it will return all the agents instead of a single one that is sorted with given sorttype and sortorder.

Furthermore, if you also indicate the inboundDate variable, then it will also return the InboundLeg just as the same as the OutboundLeg.

0 => array:4 [
  "BookingDetailsLink" => {#33
    +"Uri": "/apiservices/pricing/v1.0/adee66c72082472b8ce7165a97426dba_rrsqbjcb_06a13f0a788e803fcc56e78802891a26/booking"
    +"Body": "OutboundLegId=13554-1707011405--31734-0-12585-1707012005&InboundLegId=12585-1707081835--31734-0-13554-1707082045"
    +"Method": "PUT"
  }
  "OutboundLeg" => {#1235
    +"Id": "13554-1707011405--31734-0-12585-1707012005"
    +"SegmentIds": array:1 [
      0 => 17
    ]
    +"OriginStation": 13554
    +"DestinationStation": 12585
    +"Departure": "2017-07-01T14:05:00"
    +"Arrival": "2017-07-01T20:05:00"
    +"Duration": 240
    +"JourneyMode": "Flight"
    +"Stops": []
    +"Carriers": array:1 [
      0 => 1755
    ]
    +"OperatingCarriers": array:1 [
      0 => 1755
    ]
    +"Directionality": "Outbound"
    +"FlightNumbers": array:1 [
      0 => {#1236
        +"FlightNumber": "1990"
        +"CarrierId": 1755
        +"FlightCode": "TK1990"
        +"Carrier": {#1274
          +"Id": 1755
          +"Code": "TK"
          +"Name": "Turkish Airlines"
          +"ImageUrl": "http://s1.apideeplink.com/images/airlines/TK.png"
          +"DisplayCode": "TK"
        }
      }
    ]
  }
  "InboundLeg" => {#1245
    +"Id": "12585-1707081835--31734-0-13554-1707082045"
    +"SegmentIds": array:1 [
      0 => 7
    ]
    +"OriginStation": 12585
    +"DestinationStation": 13554
    +"Departure": "2017-07-08T18:35:00"
    +"Arrival": "2017-07-08T20:45:00"
    +"Duration": 250
    +"JourneyMode": "Flight"
    +"Stops": []
    +"Carriers": array:1 [
      0 => 1755
    ]
    +"OperatingCarriers": array:1 [
      0 => 1755
    ]
    +"Directionality": "Inbound"
    +"FlightNumbers": array:1 [
      0 => {#1246
        +"FlightNumber": "1983"
        +"CarrierId": 1755
        +"FlightCode": "TK1983"
        +"Carrier": {#1274}
      }
    ]
  }
  "Agent" => {#285
    +"QuoteAgeInMinutes": 13
    +"Price": 183.08
    +"DeeplinkUrl": "http://partners.api.skyscanner.net/apiservices/deeplink/v2?_cje=9bZBn9EG0XSSEDgJNqeSWejplS3SzHmr47vT4j4hddBllsVfNfz8iyqb3QfbWSFX&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fUK%2fen-gb%2fGBP%2fomeg%2f2%2f13554.12585.2017-07-01%2c12585.13554.2017-07-08%2fair%2ftrava%2fflights%3fitinerary%3dflight%7c-31734%7c1990%7c13554%7c2017-07-01T14%3a05%7c12585%7c2017-07-01T20%3a05%2cflight%7c-31734%7c1983%7c12585%7c2017-07-08T18%3a35%7c13554%7c2017-07-08T20%3a45%26carriers%3d-31734%26passengers%3d1%26channel%3ddataapi%26cabin_class%3deconomy%26facilitated%3dfalse%26ticket_price%3d183.08%26is_npt%3dfalse%26is_multipart%3dfalse%26client_id%3dskyscanner_b2b%26request_id%3d92440aa0-0179-41a9-9b35-30c8b92e8c2c%26deeplink_ids%3deu-central-1.prod_106be1955accde9535d79810c42c58ed%26commercial_filters%3dfalse%26q_datetime_utc%3d2017-05-26T06%3a58%3a51"
    +"Id": 3496199
    +"Name": "omegaflightstore.com"
    +"ImageUrl": "http://s1.apideeplink.com/images/websites/omeg.png"
    +"Status": "UpdatesComplete"
    +"OptimisedForMobile": false
    +"Type": "TravelAgent"
  }
]

All the variable names are the same as indicated within the SkyScanner API documentation.

Also, to save the remote carrier and agent images to a such local folder where the image urls are provided by the API call, set the image parameters like below.

$pricing->setParameters([
    'saveAgentImages' => true,
    'saveCarrierImages' => true,
    'savePath' => '/tmp/images/'
]);

Finally, if you want to get every data returned by the API, without any modification, use the get() method, instead of the getFlights() method.

Finally, if you want to get every data returned by the API, without any modification that is made by this library itself, use the get() method, instead of the getPrices() method.

use OzdemirBurak\SkyScanner\Travel\Flights\LivePricing;

$pricing = new LivePricing($apiKey = 'your-api-key', $country = 'GB', $currency = 'GBP', $locale = 'en-GB');
$pricing->setParameters([
    'adults' => 1,
    'destinationPlace' => 'IST',
    'originPlace' => 'LHR',
    'outboundDate' => date('Y-m-d', strtotime('+1 week')),
    'stops' => 0
]);
$data = $pricing->get();

Or you can only access to single property by passing a parameter to the get() method.like

$places = $pricing->get('Places');
Clone this wiki locally