API: Search by email using "List Contacts"?

Hi,



I see the "Get Contact API call only works with the “contact id” value; can I use the "List Contacts API call to search for a user using their “email address”?



Thank you!

Hi,

I see the "Get Contact API call only works with the “contact id” value; can I use the "List Contacts API call to search for a user using their “email address”?

Thank you!

Yes, you can.
/api/contacts?search=emailToSearch

Problem with this - I can specify email of another person as my “city” for example - and above search api call will return … 2 records, including the one where I added email as a “city” field - because I think it searches across multiple fields by default.

This may or may lead to security risks as you can accidentally email sensitive data to a wrong recipient if implemented directly as shown above.

It looks like to ONLY search by email - you’d have to do somthing like this, ex:

$contacts = $contactApi->getList("email:$email", 0, 30, $orderBy='email', $orderByDir='asc', $publishedOnly=false, $minimal=false);

^ note: you have to add email: prefix to only search email column.

2 Likes

A simple solution is just to use the add contact method

api/contacts/new {email:xxxxx} and it will return the ID of the contact. :slight_smile: