laravel-xero icon indicating copy to clipboard operation
laravel-xero copied to clipboard

HTTP ERROR 500 Triggering doing a simple Contacts GET request

Open DanHarrison opened this issue 1 year ago • 1 comments

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!

DanHarrison avatar May 08 '24 11:05 DanHarrison

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.

dcblogdev avatar May 08 '24 23:05 dcblogdev

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();

dcblogdev avatar May 19 '25 01:05 dcblogdev