Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contact Filter on AccountNumber doesn't filter contacts but returns all records. #47

Closed
helloadmin opened this issue Nov 5, 2023 · 3 comments

Comments

@helloadmin
Copy link

I'm using the following code Xero::contacts()->get(1, 'AccountNumber="10307"') and returns a collection of all contacts and not just the single contact where AccountNumber = 10307

When I use the more raw method of using the verbs, I get the intended result. See below.
$endpoint = 'Contacts';
$query = ['where' => 'AccountNumber="' . $accountNumber . '"',];
$result = Xero::get($endpoint, $query);

Is this a bug with Xero::contacts()->get(1, 'AccountNumber="10307"')? The format looks simple and aligns with the examples provided.

@twocngdagz
Copy link

twocngdagz commented Feb 7, 2024

@helloadmin

I was able to replicate this issue

filtering by email address returns all contact

Xero::contacts()->get(null, 'EmailAddress="email_address_here"')

I was able to find the cause:

In the guzzle method

your calling get this way ->$type(self::$baseUrl . $request, $data), which means data is empty and the query parameters for the "where" filter is concatenated with the baseUrl like here:

https://api.xero.com/api.xro/2.0/contacts?where=EmailAddress%3D%sample%40gmail.com%22

which does not work because upon inspection the query parameter does not get included in the request

The query is supposed to be something like this to work

$get('https://api.xero.com/api.xro/2.0/contacts', ['where' => 'EmailAddress="sample@gmail.com"']);

The workaround for this is something like this:

$response = Http::withToken(Xero::getAccessToken())
  ->withHeaders(["Xero-tenant-id" => Xero::getTenantId()])
  ->get("https://api.xero.com/api.xro/2.0/Contacts", [
    "where" => 'EmailAddress="sample@gmail.com"'
  ]);

For inspecting the request object you can do something like this before calling Xero and Http

Http::globalRequestMiddleware(function ($request) {
  dump($requeest)
  return $request;
});

Notice that the query attribute of the request object when using Xero::get returns empty, but if you separate the query parameter for get just like suggested above, the request object shows query value.

I can create a PR if you like, but it will take some time since I have my own integration that I need to finish. I guess this is not just happening on contact but on invoices as well if you try to use the where filter.

@dcblogdev

By the way, Thanks a lot for the package helps me a lot to speed up integrations especially how you handle token renewal, it was helpful.

@dcblogdev
Copy link
Owner

thanks, @twocngdagz really helpful reply!

Working on improving the filtering and managed to get this working without altering the public API

Xero::contacts()->get(1, ['where' => 'ContactID==Guid("74ea95ea-6e1e-435d-9c30-0dff8ae1bd80")']);

Still testing this out.

@dcblogdev
Copy link
Owner

addressed this using a new filter option #61

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants