Skip to content
Advertisement

Guzzle throws 401 or 406 exception

cURL works fine:

curl -H "X-ApiToken: myapitoken" https://api.fulcrumapp.com/api/v2/records

Guzzle does not:

$client = new Client();
$request = $client->createRequest('GET', "https://api.fulcrumapp.com/api/v2/records");
$request->setHeader("X-ApiToken:" , "myapitoken");
$response = $client->send($request);

This responds with a 401 error: not authorized. This is my first time using Guzzle but in my searches I haven’t seen this error. Seems like a simple request so I’m not sure why it is failing.

Thank you!

Advertisement

Answer

I had to add another header to explicitly tell it to handle json

$request->setHeader("Accept" , "application/json");

Thank you for pointing out that the 401 was a false error – the real error was the 406, which made me read how to actually fix that.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement