phpcurlskyscanner

sky scanner api, create booking request


I'm trying to use the skyscanner api

http://business.skyscanner.net/portal/en-GB/Documentation/FlightsLivePricingDetails

get booking details section

I'm trying to create the request for booking so I can then poll it, The data vars I am trying to put are correct, but I just get returned a server errror so I suspect my curl request is flawed

$apiKey ='keygoeshere';
$Session = $_GET["session"];
$apiSessionUrl ='http://partners.api.skyscanner.net/apiservices/pricing/v1.0/'.$Session.'/booking';

$OutboundLegId = $_GET['OutboundLegId'];
$InboundLegId = $_GET['InboundLegId'];
$data = array('apiKey'=>$apiKey,'OutboundLegId' => $_GET['OutboundLegId'],'InboundLegId' => $InboundLegId);
$dataVars = http_build_query($data);

$ch = curl_init();

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_URL, $apiSessionUrl );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $dataVars);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);

Any Help much appreciated.


Solution

  • Add the content length header as you are using PUT request.

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($dataVars)));