Encountering 405 Error When Initiating Skyscanner Flight Session via PHP

When attempting to create a flight session via POST in PHP with Skyscanner API, I receive a 405 error without the expected location header, though other headers return correctly.

<?php
require_once 'library/HttpClient.php';

$reqHeaders = [
    "API-Host" => "example-flights.com",
    "API-Key" => "abc123xyz789",
    "Content-Type" => "application/x-www-form-urlencoded"
];

$postParams = [
    "departDate"    => "2022-06-15",
    "travelClass"   => "economy",
    "kids"          => 0,
    "infants"       => 0,
    "nation"        => "US",
    "money"         => "USD",
    "lang"          => "en-US",
    "startCity"     => "NYC-sky",
    "endCity"       => "LAX-sky",
    "returnDate"    => "2022-06-20",
    "adults"        => 1
];

$responseData = \HttpClient::sendRequest("https://api.example.com/sessions", "POST", $reqHeaders, $postParams);
print_r($responseData);
?>

In my experience with similar APIs, a 405 error often indicates that the method used doesn’t match what the endpoint expects. It is useful to recheck the API documentation to ensure that the POST method is indeed allowed for creating a flight session. Additionally, examining any differences between sample code and your implementation may reveal issues such as header formatting or parameter naming conventions. In one project, switching to the recommended content type and verifying parameter order resolved the issue, so double-check these areas may help in your case as well.

hey, i had a similar issue before. sometimes the endpoint expects a json body, not form encoded. try converting your post data and header accordingly, and double-check the docs for any note on the required method or content-type.