Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > Getting Started >

Searching contacts with wildcard with thinktree / PHP-Xero

Started by Lap Nguyen -   in Getting Started

How do I use wildcard searching with the php-xero class? I'm trying to search a ContactNumber with "(888) 888 888" for example.

$result = $xero->Contacts(false, false, array(ContactNumber=>"where%3DContactNumber.Contains%28%22888%22%29"));

Please give me an example for a wilcard search?
Also please give me an example for searching "(888) 888 888".

I also tried %28888%29+888+888 via urlencode.


We do not support wild card searching - to see what our API supports in terms of search filters, please see our documentation: http://developer.xero.com/api-overview/http-get/

In addition, I note you are searching on ContactNumber. From your query, it looks like you have misunderstood the purpose of the ContactNumber element - this is not a phone number. Please review our documentation on Contacts: http://blog.xero.com/developer/api/contacts/ - you need to be using one of the Phones fields, of which there are 4 types (http://blog.xero.com/developer/api/types/#Phones)

So to search the default phone number of a contact, you might do:
GET /api.xro/2.0/Contacts?where=Phones[0].PhoneNumber.Contains("888")

To be honest, this type of searching against the API is a bit inefficient as you may need to run it against all 4 phone types. You may just want to retrieve all contacts and then do the search on your side, which would also allow for wildcard searches.
Retrieving recently updated or added contacts can be done using the If modified since parameter, allowing you to keep data in sync.

Ronan Quirke (Community Manager)  

Hi Ronan. The misunderstanding of the ContactNumber parameter is easy to make because of the API response to an already existing phone number:
"A validation exception occurred (10, ValidationException) The contact number +331234567890 is already assigned to another contact. The contact number must be unique across all contacts."

It might be a good idea to update that response to state phone number instead. Also it is a shame that the API does not support searching by phone number natively because of the error above. If phone numbers must be unique across contacts then it would be useful to be able to search for that number prior to attempting to create a new contact.

Daniel Wilson