# Search for users by email with multiple emails

**URL:** <https://community.hubspot.com/t/search-for-users-by-email-with-multiple-emails/44090>\
**Category:** APIs & Integrations\
**Tags:** professional\
**Created:** [September 20, 2021, 7:55pm UTC](https://community.hubspot.com/t/search-for-users-by-email-with-multiple-emails/44090 "2021-09-20T19:55:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JAnderson1](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/janderson1/32/64675_2.png) [@JAnderson1](https://community.hubspot.com/u/JAnderson1)\
**Post date:** [September 20, 2021, 7:55pm UTC](https://community.hubspot.com/t/search-for-users-by-email-with-multiple-emails/44090/1 "2021-09-20T19:55:16Z")

</div>

Hi,

I have a user with a secondary and a primary email. What API call do I use to find the user by primary or secondary email? This call fails to return any results. I tried both hs\_additonal\_emails and email as the field:

POST [https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=X](https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=X) HTTP/1.1  
Accept: application/json  
Content-Type: application/json  
Host: [api.hubapi.com](http://api.hubapi.com)  
Content-Length: 721  
Expect: 100-continue  
Connection: Keep-Alive

{  
“filterGroups”: [  
{  
“filters”: [  
{  
“value”: “[it@iii.com](mailto:it@iii.com)”,  
“propertyName”: “hs\_additional\_emails”,  
“operator”: “CONTAINS\_TOKEN”  
}  
]  
}  
],  
“sorts”: [],  
“limit”: 100  
}

 ![emails.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/2/8/28c88fc4732912268faff59c6104912ad0143882.png)

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [September 21, 2021, 6:47am UTC](https://community.hubspot.com/t/search-for-users-by-email-with-multiple-emails/44090/2 "2021-09-21T06:47:51Z")

</div>

Hi @JAnderson1 ,

I copied the solution of this [post](https://community.hubspot.com/t5/APIs-Integrations/Search-Contacts-for-Secondary-Mail/td-p/358756), might help you out. I see that the code matches your code. But I tested this solution with Postman, and the described setup below should work. I could find my contact with my primary email but also with my secondary email.

Using the EQ operator when searching on the ‘email’ property won’t return contacts based on their secondary emails; it’ll only return contacts with a primary email that matches the search term.

What you might consider doing instead (or in combination) is using the CONTAINS\_TOKEN operator and searching the ‘hs\_additional\_emails’ field. Here’s an example body that should do the trick:

```lia-code-sample
{
 "filterGroups": [
 {
 "filters": [
 {
 "value": "((email))",
 "propertyName": "hs_additional_emails",
 "operator": "CONTAINS_TOKEN"
 }
 ]
 },
 {
 "filters": [
 {
 "value": "((email))",
 "propertyName": "email",
 "operator": "EQ"
 }
 ]
 }
 ]
}

```

---

<div class="post-metadata">

**Author:** ![JAnderson1](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/janderson1/32/64675_2.png) [@JAnderson1](https://community.hubspot.com/u/JAnderson1)\
**Post date:** [September 21, 2021, 7:03pm UTC](https://community.hubspot.com/t/search-for-users-by-email-with-multiple-emails/44090/3 "2021-09-21T19:03:42Z")

</div>

Hi,

Thanks for the code.

I tried the JSON, but the contact fails to return:

POST [https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=X](https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=X)

{  
“filterGroups”: [  
{  
“filters”: [  
{  
“value”: “EMAIL”,  
“propertyName”: “hs\_additional\_emails”,  
“operator”: “CONTAINS\_TOKEN”  
}  
]  
},  
{  
“filters”: [  
{  
“value”: “EMAIL”,  
“propertyName”: “email”,  
“operator”: “EQ”  
}  
]  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [September 21, 2021, 7:15pm UTC](https://community.hubspot.com/t/search-for-users-by-email-with-multiple-emails/44090/4 "2021-09-21T19:15:48Z")

</div>

This is really odd. What programming language are you using? I tested the above body with Postman and was able to get the results.  
Is your hapikey valid?

---

<div class="post-metadata">

**Author:** ![IMykhayliv](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/imykhayliv/32/9140_2.png) [@IMykhayliv](https://community.hubspot.com/u/IMykhayliv)\
**Post date:** [September 21, 2021, 8:03pm UTC](https://community.hubspot.com/t/search-for-users-by-email-with-multiple-emails/44090/5 "2021-09-21T20:03:38Z")

</div>

Hello again, Teun. We looked into it further, and we were able to resolve the issue - it turns out that, in line with the API, we needed to have multiple filter groups, with 1 filter each for the necessary OR comparison, as described below:

> **[Search the CRM - HubSpot docs](https://developers.hubspot.com/docs/api-reference/latest/crm/search-the-crm)**
>
> The CRM search endpoints make getting data more efficient by allowing developers to filter, sort, and search across any CRM object type.

“When multiple filters are provided within a filterGroup, they will be combined using a logical AND operator. When multiple filterGroups are provided, they will be combined using a logical OR operator. The system supports a maximum of three filterGroups with up to three filters each.”

And when removing the extra filter in the 1st group in the curl example on the page, the JSON structure matches your recommended format:

“curl [https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=YOUR\_HUBSPOT\_API\_KEY](https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=YOUR_HUBSPOT_API_KEY) \  
--request POST \  
--header “Content-Type: application/json” \  
--data ‘{  
“filterGroups”:[  
{  
“filters”: [  
{  
“propertyName”: “firstname”,  
“operator”: “EQ”,  
“value”: “Alice”  
}  
]  
},  
{  
“filters”: [  
{  
“propertyName”: “enum1”,  
“operator”: “HAS\_PROPERTY”  
}  
]  
}  
]  
}’”

Thank you for your help, and have a great day. We can consider the matter closed.

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [September 21, 2021, 8:05pm UTC](https://community.hubspot.com/t/search-for-users-by-email-with-multiple-emails/44090/6 "2021-09-21T20:05:57Z")

</div>

Awesome! Happy to help!

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [September 22, 2021, 5:29pm UTC](https://community.hubspot.com/t/search-for-users-by-email-with-multiple-emails/44090/7 "2021-09-22T17:29:25Z")

</div>

Awesome, happy that you we’re able to resolve it!
