Find contacts by several fields (OR)

Hi. My question is can we make an API request to find contacts by several fields?
My case is to find a contact by phone number. But it can be PHONE1 or PHONE2. Is there a possibility to make ONE request to search by two fields? From what I see in docs we can only find a contact by email or by one field (DataService.findByField) or make a DataService.query requests.
DataService.query request allows to make complicated query but as far as I understand from examples and docs it only allows ‘AND’ queries but I need ‘OR’ query.
Kind of ‘select from contacts where PHONE1=123 OR PHONE2=123’ :smiley:

Hi @Steve_Osler, the findByField method only takes one field as its criteria per call. This would require 2 calls, one call for PHONE1 and one call for PHONE2. Unfortunately, DataService.query, will use AND in order to find a matching record.

For example:

<?xml version='1.0' encoding='UTF-8'?>
<methodCall>
  <methodName>DataService.query</methodName>
  <params>
    <param>
      <value><string>{{APIKey}}</string></value>
    </param>
    <param>
      <value><string>Contact</string></value>
    </param>
    <param>
      <value><int>1000</int></value>
    </param>
    <param>
      <value><int>0</int></value>
    </param>
    <param>
      <value><struct>
      	<member><name>PHONE1</name>
          <value><string>(480) 442-2222</string></value>
        </member>
        <member><name>PHONE2</name>
          <value><string>(480) 442-2222</string></value>
        </member>
      </struct></value>
    </param>
    <param>
      <value><array>
        <data>
          <value><string>Id</string></value>
          <value><string>FirstName</string></value>
          <value><string>Email</string></value>
        </data>
      </array></value>
    </param>
    <param>
      <value><string>Id</string></value>
    </param>
    <param>
      <value><boolean>1</boolean></value>
    </param>
  </params>
</methodCall>

would only match a contact whose PHONE1 AND PHONE2 are (480) 442-2222

@Carlos_Ochoa Is anything changed recently around this ? Can we search by Phone1 or Phone2 or Phone3.

I am implementing an api integration to look up contact on every call made to a contact. sometimes i need search through phone5 and it takes 5 api calls to find a contacts.

This is eating up my limit of 1500 calls per minute when we have 100s of calls per minute in an organization.

@Vishnu_Ghule I don’t think anything has been changed in this, it is still an “AND”.

The only way I have really found to get around this is to keep a copy of the data you care about, in this case Contacts, on your server and regularly keeping it updated. Then on your server you can do a query on your copy of the data however you want.

There are various ways to keep a copy of the data, from fully pulling your list on a regular basis via the XML-RPC part of the API or by using the REST API to respond to whenever a contact is changed (added/updated/deleted/tagged/untagged), or a combination of both API, depending on your needs.

For instance, we keep a copy of the data on our site by running a full sync of the Contact table via the XML-RPC part of the API about once a day, then use the REST API to respond to when a contact is changed immediately. That way it is only a few calls a day to get a full sync (XML-RPC), and depending on what happens in the day a few more calls to keep the data as updated as possible (REST).

Then we can query and utilize our site’s copy of the data as much as we need without using any further API calls or worrying about hitting the calls per minute limit.