laravel-xero
laravel-xero copied to clipboard
HTTP ERROR 500 Triggering doing a simple Contacts GET request
I love the work this library does to make it easier to refresh the oauth token. But I've hit an issue doing a simple request:
$email = '[email protected]';
$data = Xero::contacts()->get( 1, 'EmailAddress="' . $email . '"' );
and I have a simple Laravel route to test this. But the page returns HTTP ERROR 500. Spending a couple of hours digging into the code, I've found this in guzzle():
try {
$response = Http::withToken($this->getAccessToken())
->withHeaders(array_merge(['Xero-tenant-id' => $this->getTenantId()], $headers))
->accept($accept)
->$type(self::$baseUrl . $request, $data)
->throw();
return [
'body' => $raw ? $response->body() : $response->json(),
'headers' => $response->getHeaders()
];
And this basically passes an empty array to the get() method in PendingRequest().
When I removed $data from ->$type(self::$baseUrl . $request, $data) - the code works great. I can't quite tell why this code causes such a fuss if query is empty.
I'm not sure if it's related to issue #47, it might be.
Any thoughts appreciated!
Thanks, Yes I think it is related, I noticed the where wasn't taking effecting I've written out a new way to work for filtering, I need to do a release and update the docs doing a bit more testing before I do. I'll pick this up tomorrow.
sorry for the delay, You can now for filtering this way:
Can be chained or written out separately
$query = Xero::contacts();
if ($this->accountNumber) {
$query->filter('where', 'AccountNumber=="'.$this->accountNumber.'"');
}
if ($this->email) {
$query->filter('where', 'EmailAddress=="'.$this->email.'"');
}
if ($this->contactId) {
$query->filter('where', 'ContactID==Guid("'.$this->contactId.'")');
}
if ($this->searchTerm) {
$query->filter('searchTerm', $this->searchTerm);
}
if ($this->includeArchived) {
$query->filter('includeArchived', $this->includeArchived);
}
$query->filter('order', 'name');
return $query->get();