cURL works fine:
JavaScript
x
curl -H "X-ApiToken: myapitoken" https://api.fulcrumapp.com/api/v2/records
Guzzle does not:
JavaScript
$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
JavaScript
$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.