Searching for a contact by additional emails

I have contacts with multiple emails. Let’s take this one for example:

email: main@gmail.com

additional1: add1@gmail.com

additional2: add2@gmail.com

When fetching that contact from the API (and requesting hs_additional_emails), i get:

{
 "email": "main@gmail.com",
 "hs_additional_emails": "add1@gmail.com;add2@gmail.com"
}

The problem is when I search for contacts with the email/hs_additional_emails “add1@gmail.com”, I don’t get anything.

I’ve tried using IN, EQ and CONTAINS_TOKEN and nothing works. Tried for both email and for the property hs_additional_emails.

Any ideas?

Hey @oshaked - thanks for posting in the Community!
I’d like to tag in a few experts here to see if they have any insight for us!
@eburnaman, @Phil_Vallender, and @Mike_Eastwood - any thoughts here?
Shane, Community Manager

@oshaked - can you offer an example of the search filter JSON that isn’t working for this case?

Steve

Hi @oshaked

You will need to set up filter groups to search for each query individually, with an OR clause.

This is a simplified version to show the concept:

WHERE
"email" EQUALS "main@gmail.com"
OR
"hs_additional_emails" CONTAINS "add1@gmail.com"
OR
"hs_additional_emails" CONTAINS "add2@gmail.com"

Have a look at this link Search the CRM - HubSpot docs

It takes a while to get your head around it but it’s worth the effort.

I usually test my filters using Postman until I can get it to work.

Have fun

Mike

p.s. thank you for the mention @STierney

Here to learn more about HubSpot and share my HubSpot Knowledge. I’m the founder of Webalite a Gold HubSpot Partner Agency based in Wellington, New Zealand and the founder of Portal-iQ the world’s first automated HubSpot Portal Audit that helps you work smarter with HubSpot.

Unfortunately, that doesn’t work for me.

I have two contacts. First contact with email one@gmail.com, second contact with multple emails: primary email somethingElse@gmail.com, additional emails two@gmail.com and three@gmail.com.

My search query looks like this, but it doesn’t find the second contact:

curl https://api.hubapi.com/crm/v3/objects/contacts/search \
 --request POST \
 --header "Content-Type: application/json" \
 --header "authorization: Bearer MY_TOKEN" \
 --data '{
 "filterGroups": [
 {
 "filters": [
 {
 "propertyName": "email",
 "operator": "IN",
 "values": ["one@gmail.com", "two@gmail.com", "three@gmail.com"]
 }
 ]
 },
 {
 "filters": [
 {
 "propertyName": "hs_additional_emails",
 "operator": "CONTAINS_TOKEN",
 "value": "one@gmail.com"
 }
 ]
 },
 {
 "filters": [
 {
 "propertyName": "hs_additional_emails",
 "operator": "CONTAINS_TOKEN",
 "value": "two@gmail.com"
 }
 ]
 },
 {
 "filters": [
 {
 "propertyName": "hs_additional_emails",
 "operator": "CONTAINS_TOKEN",
 "value": "three@gmail.com"
 }
 ]
 },
 ]
}'

Hi @oshaked
You can use the provided CURL below to search contacts
Here is the curl for the contact search API

curl --location 'https://api.hubapi.com/crm/v3/objects/contacts/search' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ${token}' \
--data '{
 ""filterGroups"": [
 {
 ""filters"": [
 {
 ""propertyName"": ""email"",
 ""operator"": ""EQ"",
 ""value"": """"
 }
 ]
 }
 ],
 ""properties"":[""file_test""]
}'"

I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.

Thanks!

Thanks but that doesn’t help at all. Please read the entire thread and see what I’ve already tried.

Hey @oshaked - thanks for confirming that this did not work.
@Mike_Eastwood and @GRajput - any follow up thoughts here?
Shane, Community Manager