I am developing a web app that connects to Xero's API to fetch Contacts and Invoices using Laravel Xero. At first it was fetching the data properly. Then the cURL 18 error started to appear erratically. And now the error has become permanent.
Checking Xero's Developer dashboard, the calls I make apparently get a status 200 which makes me believe that the error is truly from my end.
Here's the code when making the call:
protected function guzzle ($type, $request, $data = [], $raw = false)
{
try {
$client = new Client;
$headers = [
'Accept' => 'application/json',
'Authorization' => 'Bearer '.$this->getAccessToken(),
'Xero-tenant-id' => $this->getTenantId(),
'Accept-Encoding' => 'gzip, deflate',
];
$response = $client->$type(self::$baseUrl.$request, [
'headers' => $headers,
'body' => $raw ? $data : json_encode($data),
]);
return [
'body' => json_decode($response->getBody()->getContents(), true),
'headers' => $response->getHeaders()
];
} catch (ClientException $e) {
throw new Exception($e->getResponse()->getBody()->getContents());
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
The cURL 18 error starts to appear upon $response
, with the exception being caught at the catch (Exception $e)
function.
I have tried virtually every suggestion found on the web and haven't had any success.
Thank you in advance for any help.
For Reference: cURL error 18: Transfer closed with outstanding read data remaining