I’d like to look up contacts by phone number over the API when an email address is not available.
I’ve tried both DataService.query and DataService.findByField with no luck.
Taking a known phone number in from the Phone1 field in an existing contact record (ie (555) 555-5555), I am able to look up records by that number in the web interface. I am not able to find records using the same number over the API with ‘query’ or ‘findByField’. I tested the following values against Phone1.
555
5555555555
(555) 555-5555
%5%
Is there anything special about querying a phone field?
I tried sending just ‘Phone’ as the field name and got an appropriate error. For good measure, I tried this process with multiple phone numbers.
At this point I feel like there must be something really obvious I am missing.
If it matters, I’m working with the Novak PHP SDK. Sample code:
private function lookupInfusionsoftContactByPhone($phone) {
return $this->lookupInfusionsoftRecord('Phone1', $phone);
}
private function lookupInfusionsoftRecord($key, $value) {
return \Infusionsoft_DataService::findByField(
new \Infusionsoft_Contact(),
$key, $value, null, null, false, $this->infusionsoft );
}
You cannot trust that the format of the phone number field will be consistent. There are too many variations. This, as I’m sure you are seeing, creates a difficulty in your case as the query is a string literal query. If the phone numbers were pre-filterable then that would be different. The only way to be sure in your case is to remove all non-number characters and then compare, which you can’t do until the information is pulled from IS. I might consider a small script that takes the phone number, strips all non numerics and then stored the number only value in a custom field. Then you would have a more reliable query when you needed it.
The way you mentioned above works just fine and it really helped me a lot for searching contacts on IFS with phone numbers, irrespective of the format they are saved in.