PHP Skyscanner API: 405 error on POST request for flight search session

Help! I’m stuck with a 405 error

I’m working on a PHP project using the Skyscanner flight search API. I’m trying to create a session with a POST request but I keep receiving a 405 error. Oddly, I’m getting responses for other aspects, just not the location header I need.

Here’s a simplified version of my code:

$response = SomeAPIClient::post('flights/search', [
  'headers' => [
    'API-Key' => 'my_secret_key',
    'Content-Type' => 'application/x-www-form-urlencoded'
  ],
  'body' => [
    'from' => 'NYC',
    'to' => 'LAX',
    'date' => '2023-06-15',
    'passengers' => 1
  ]
]);

print_r($response);

I expected to get a response with a location header but instead, I’m seeing a 405 Method Not Allowed error. Any ideas on what I might be doing wrong? I’m pretty sure my API key is correct, so could it be related to my request format?

The 405 error typically indicates that the method you are using is not permitted for the endpoint. It might be that the ‘/flights/search’ endpoint is intended for a different HTTP method than POST. I would first verify the API documentation to ensure the correct method is being used for this operation. Additionally, confirm whether your parameters should be sent in the body or as query parameters, and check the Content-Type header – some endpoints may require ‘application/json’ rather than ‘application/x-www-form-urlencoded’.

hey alex, i had similar issues. make sure ur using the right endpoint. skyscanner changed their api recently. try ‘flights/live/search’ instead of ‘flights/search’. also, check if u need to send the data as json. might need to change ur content-type header. good luck!

I’ve dealt with Skyscanner API issues before, and 405 errors can be tricky. Have you tried using a different HTTP client library? Sometimes the built-in PHP cURL functions or Guzzle can handle these requests better. Also, double-check your API credentials - even if you think they’re correct, it’s worth regenerating them just to be sure. One thing that helped me was setting up detailed logging for the API calls. It gave me more insight into what was actually being sent and received. Lastly, consider reaching out to Skyscanner support directly. They were surprisingly helpful when I hit a wall with a similar issue.