How tp retrieve all contacts with a specific email address

I want to retrieve all contacts with specific email in HubSpot.

I ran the following command

curl https://api.hubapi.com/crm/v3/objects/contacts/search \
--request POST \
--header “Content-Type: application/json” \
--header “Authorization: <val>” \
--data ‘{ “filterGroups”:[ { “filters”:[ { “propertyName”: “email”, “operator”: “EQ”, “value”: “<value>” } ] } ] }’

The result was empty:

{“total”:0,“results”:[]}

What did I do wrong?

Hey, @yorambaron :waving_hand: Thanks for the great question.

Have you tried using the CONTAINS_TOKEN operator? This allows you to search for partial values by using a wildcard. For example, use the value *@hubspot.com to retrieve contacts with a HubSpot email address.

Here’s an example I just did with postman. I have several contacts in my test portal who have an email address that use bobsburgers.com as a fake domain.

  • I have 7 contacts that use this domain

  • Request
    https://api.hubapi.com/crm/v3/objects/contacts/search​

  • Request body

    {
     "filterGroups": [
     {
     "filters": [
     {
     "propertyName": "email",
     "operator": "CONTAINS_TOKEN",
     "value": "*@bobsburgers.com"
     }
     ]
     }
     ]
    }​
    
  • Response

    {
     "total": 7,
     "results": [
     {
     "id": "801",
     "properties": {
     "createdate": "2022-11-03T21:42:31.255Z",
     "email": "louise@bobsburgers.com",
     "firstname": "Louise",
     "hs_object_id": "801",
     "lastmodifieddate": "2023-03-23T01:06:41.059Z",
     "lastname": "Belcher"
     },
     "createdAt": "2022-11-03T21:42:31.255Z",
     "updatedAt": "2023-03-23T01:06:41.059Z",
     "archived": false
     },
     {
     "id": "851",
     "properties": {
     "createdate": "2022-11-03T21:42:31.255Z",
     "email": "linda@bobsburgers.com",
     "firstname": "Linda",
     "hs_object_id": "851",
     "lastmodifieddate": "2023-03-23T01:04:59.503Z",
     "lastname": "Belcher"
     },
     "createdAt": "2022-11-03T21:42:31.255Z",
     "updatedAt": "2023-03-23T01:04:59.503Z",
     "archived": false
     },
     {
     "id": "901",
     "properties": {
     "createdate": "2022-11-03T21:42:31.255Z",
     "email": "bob@bobsburgers.com",
     "firstname": "Bob",
     "hs_object_id": "901",
     "lastmodifieddate": "2023-03-17T20:49:02.694Z",
     "lastname": "Belcher"
     },
     "createdAt": "2022-11-03T21:42:31.255Z",
     "updatedAt": "2023-03-17T20:49:02.694Z",
     "archived": false
     },
     {
     "id": "951",
     "properties": {
     "createdate": "2022-11-03T21:42:31.255Z",
     "email": "gene@bobsburgers.com",
     "firstname": "Gene",
     "hs_object_id": "951",
     "lastmodifieddate": "2023-03-23T01:06:02.731Z",
     "lastname": "Belcher"
     },
     "createdAt": "2022-11-03T21:42:31.255Z",
     "updatedAt": "2023-03-23T01:06:02.731Z",
     "archived": false
     },
     {
     "id": "1001",
     "properties": {
     "createdate": "2022-11-03T21:42:31.255Z",
     "email": "tina@bobsburgers.com",
     "firstname": "Tina",
     "hs_object_id": "1001",
     "lastmodifieddate": "2023-03-23T01:06:46.276Z",
     "lastname": "Belcher"
     },
     "createdAt": "2022-11-03T21:42:31.255Z",
     "updatedAt": "2023-03-23T01:06:46.276Z",
     "archived": false
     },
     {
     "id": "1501",
     "properties": {
     "createdate": "2023-02-16T19:08:48.222Z",
     "email": "teddy@bobsburgers.com",
     "firstname": "Teddy",
     "hs_object_id": "1501",
     "lastmodifieddate": "2023-03-23T01:05:57.561Z",
     "lastname": null
     },
     "createdAt": "2023-02-16T19:08:48.222Z",
     "updatedAt": "2023-03-23T01:05:57.561Z",
     "archived": false
     },
     {
     "id": "1601",
     "properties": {
     "createdate": "2023-02-28T21:00:31.567Z",
     "email": "mort@bobsburgers.com",
     "firstname": "Mort",
     "hs_object_id": "1601",
     "lastmodifieddate": "2023-03-23T01:04:59.985Z",
     "lastname": null
     },
     "createdAt": "2023-02-28T21:00:31.567Z",
     "updatedAt": "2023-03-23T01:04:59.985Z",
     "archived": false
     }
     ]
    }​
    

Have fun building! — Jaycee