Hi.
The asterisk is a valid character in the email, so we want to treat the asterisk character literally in the email property of Contacts. Creating a contact with an asterisk character in the email via the API works as expected:
POST https://api.hubapi.com/crm/v3/objects/contacts
{
"properties": {
"firstname": "Jane",
"lastname": "Smith",
"email": "j*h@example.com"
}
}
creates a Contact with:
"email": "j*h@example.com"
But searching by email with EQ treats the “*” as a wildcard characted instead of literally. For example:
POST https://api.hubapi.com/crm/v3/objects/contacts/search
{
"filterGroups": [
{
"filters": [
{
"propertyName": "email",
"operator": "EQ",
"value": "j*h@example.com"
}
]
}
]
}
responds with all the Contacts that have j*(something)*h@example.com as email and we expected to get just the Contact created above, that has j*h@example.com as email, with the literal “*”.
Adding a secondary email with a literal “*” also works as expected:
PUT https://api.hubapi.com/contacts/v1/secondary-email/42/email/b*h@55places.com
And surprisingly, searching by hs_additional_emails with the CONTAINS_TOKEN operator also seems to treat the “*” literally. For example:
POST https://api.hubapi.com/crm/v3/objects/contacts/search
{
"filterGroups": [
{
"filters": [
{
"propertyName": "hs_additional_emails",
"operator": "CONTAINS_TOKEN"
"value": "b*h@55places.com",
}
]
}
]
}
responds with just the Contact that was updated above with the literal “b*h@55places.com” secondary email, and does not include any other Contact that have b*(something)*h@example.com as secondary email.
This is surprising because the Search the CRM - HubSpot docs documentation mentions how the “*” works the other way around. Namely:
| EQ | Equal to |
|---|---|
| … | |
| CONTAINS_TOKEN | Contains a token. In your request, you can use wildcards (*) to complete a partial search. For example, use the value *@hubspot.com to retrieve contacts with a HubSpot email address. |
So our question is: How can we reliably search for Contacts both by email and hs_additional_emails using values that contains a “*” character that will be treated literally instead of as a wildcard in both properties?
For example:
POST https://api.hubapi.com/crm/v3/objects/contacts/search
{
"filterGroups": [
{
"filters": [
{
"propertyName": "email",
"operator": "EQ"
"value": "b*h@55places.com",
}
]
},
{
"filters": [
{
"propertyName": "hs_additional_emails",
"operator": "CONTAINS_TOKEN"
"value": "b*h@55places.com",
}
]
}
]
}
should return only one Contact that contains either a primary email “b*h@55places.com” or a secondary email “b*h@55places.com”, if such Contact exists, treating the “*” as a literal character when searching both properties.
EDIT: Forgot to also ask: Is there any character other than “*” that we should be careful about because it can also work as an wildcard in the search API?