I’m working with a flight booking API through RapidAPI and having trouble with my POST request. When I try to create a new pricing session, I keep getting a 405 Method Not Allowed error instead of the expected response with the location header.
Here’s my current code:
require_once 'vendor/autoload.php';
require_once 'vendor/mashape/unirest-php/src/Unirest.php';
$result = Unirest\Request::post("https://travel-flight-api-v1.p.rapidapi.com/apiservices/search/v1.0",
array(
"X-RapidAPI-Host" => "travel-flight-api-v1.p.rapidapi.com",
"X-RapidAPI-Key" => "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz",
"Content-Type" => "application/x-www-form-urlencoded"
),
array(
"departureDate" => "2024-05-15",
"travelClass" => "economy",
"childCount" => 0,
"infantCount" => 0,
"countryCode" => "US",
"currencyCode" => "USD",
"localeCode" => "en-US",
"fromLocation" => "LAX-sky",
"toLocation" => "JFK-sky",
"returnDate" => "2024-05-20",
"passengerCount" => 2
)
);
var_dump($result);
I should be getting headers like this:
cache-control: private
content-type: application/json
date: Mon, 15 Apr 2024 10:30:15 GMT
location: http://partners.api.travel.net/apiservices/search/us1/v1.0/12ab34cd-567e-89fg-hij1-234567890klm
server: RapidAPI-1.2.8
But instead, I’m getting this error response with a 405 status code and an empty body. The headers indicate Method Not Allowed, but I’m sure I’m using POST correctly. What could be causing this issue?