repository.Contacts.Where(c => c.Name.Contains("M"));
Closed this issue · 2 comments
running this
repository.Contacts.Where(c => c.Name.Contains("M"));
results in this:
The method 'Contains' can't currently be used in a XeroApi WHERE querystring.
In ApiQueryTranslator.cs I tried to quickly just move: case "Contains": up to line 40 (under case "Where":) but that just mangled it and I got the "is not a Boolean" error. (it modified the _query.Where to "Name(/"M/")".
Happy to look into this further and fix, but just want to make sure I'll be doing the right thing, and something worthwhile
As far as I know the Xero API doesn't support filtering like that. If you look on https://api.xero.com and (after granting it access to an application) look at the Contacts dropdown option you'll see what the API supports.
If you want to use Contains you'll have to download (and cache) the entire contacts list locally and then run your query on that collection instead rather than the API.
EDIT:
Actually I take it back. After following my own instructions I managed to put some code into the where clause. The QueryTranslator would need modifying to pass the code straight through though.
Name.Contains("M")
Name.StartsWith("M")
Check out: http://blog.xero.com/developer/api-overview/http-get/
Down in the "Additional Custom Filters" section, it has "Contains" and "StartsWith" etc.
GET /api.xro/2.0/Invoices?where=Name.Contains%28%22Peter%22%29
Name.Contains("Peter")
I did initially think that maybe I should move the query somewhere else or do it differently, but the intellisense was working with the way I did it above, and I couldn't come up with another way of specifying it.