I’m working with a travel booking API through RapidAPI and having trouble with creating a flight search session. When I send a POST request to initialize the search, I keep getting a 405 Method Not Allowed error instead of the expected location header in the response.
require_once 'vendor/autoload.php';
require_once 'vendor/mashape/unirest-php/src/Unirest.php';
$apiResponse = Unirest\Request::post("https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/pricing/v1.0",
array(
"X-RapidAPI-Host" => "skyscanner-skyscanner-flight-search-v1.p.rapidapi.com",
"X-RapidAPI-Key" => "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz",
"Content-Type" => "application/x-www-form-urlencoded"
),
array(
"returnDate" => "2024-06-15",
"seatClass" => "economy",
"childCount" => 0,
"infantCount" => 0,
"countryCode" => "US",
"currencyCode" => "USD",
"localeCode" => "en-US",
"departureAirport" => "LAX-sky",
"arrivalAirport" => "JFK-sky",
"departureDate" => "2024-06-10",
"passengerCount" => 2
)
);
var_dump($apiResponse);
I should be getting headers like this:
"cache-control": "private"
"content-type": "application/json"
"date": "Thu, 15 Feb 2024 10:30:22 GMT"
"location": "http://partners.api.skyscanner.net/apiservices/pricing/us2/v1.0/8f3e21a5-902b-4c7a-b8f4-d9e6c5a4b3f2"
"server": "RapidAPI-1.0.20"
But instead I’m getting a 405 error with empty response body. The API documentation says this endpoint should accept POST requests, so I’m not sure what’s wrong with my implementation. Has anyone encountered this issue before?