paulbrejla / ferien-api

Code for ferien-api.de lives here. Feel free to contribute.
https://ferien-api.de
MIT License
23 stars 1 forks source link

Question: Method not allowed #17

Closed ThomasKujawa closed 2 years ago

ThomasKujawa commented 2 years ago

I get an HTTP405 when I run the following code:

$url = 'https://ferien-api.de/api/v1/holidays/'; $url .= $bundeslaender[$bundesland]; $url .= '/'; $url .= $jahr; dump($url); $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, ['X-DFA-Token: dfa',]); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($curl, CURLOPT_TIMEOUT, 1); //timeout in seconds $response = curl_exec($curl); curl_close($curl); $rueckgabe = json_decode($response, true); dump($rueckgabe);

The two outputs (dump) result in the following:

string(45) "https://ferien-api.de/api/v1/holidays/HH/2022"

array(5) {
  ["timestamp"]=>
  string(29) "2022-09-13T15:39:39.762+00:00"
  ["status"]=>
  int(405)
  ["error"]=>
  string(18) "Method Not Allowed"
  ["message"]=>
  string(0) ""
  ["path"]=>
  string(24) "/api/v1/holidays/HH/2022"
}

When I call the received url https://ferien-api.de/api/v1/holidays/HH/2022 directly, I get the correct output:

[{"start":"2022-01-28T00:00Z","end":"2022-01-29T00:00Z","year":2022,"stateCode":"HH","name":"winterferien","slug":"winterferien-2022-HH"},{"start":"2022-03-07T00:00Z","end":"2022-03-19T00:00Z","year":2022,"stateCode":"HH","name":"osterferien","slug":"osterferien-2022-HH"},{"start":"2022-05-23T00:00Z","end":"2022-05-28T00:00Z","year":2022,"stateCode":"HH","name":"pfingstferien","slug":"pfingstferien-2022-HH"},{"start":"2022-07-07T00:00Z","end":"2022-08-18T00:00Z","year":2022,"stateCode":"HH","name":"sommerferien","slug":"sommerferien-2022-HH"},{"start":"2022-10-10T00:00Z","end":"2022-10-22T00:00Z","year":2022,"stateCode":"HH","name":"herbstferien","slug":"herbstferien-2022-HH"},{"start":"2022-12-23T00:00Z","end":"2023-01-07T00:00Z","year":2022,"stateCode":"HH","name":"weihnachtsferien","slug":"weihnachtsferien-2022-HH"}]

Where is my mistake? What am I doing wrong?

paulbrejla commented 2 years ago

You are sending a post request to an endpoint that only supports get.

I am not that familiar with curl but this seems to be the line: _ curl_setopt($curl, CURLOPTPOST, 1);

ThomasKujawa commented 2 years ago

Oh man, this is embarrassing.

Always this cut and paste.