Understanding CONTAINS_TOKEN operator for CRM Search

Hi,

My understanding of the CONTAINS_TOKEN operator used in the CRM search API is that if a string has part of a substring matched, it should return that contact. I am using the api to find contacts based on their phone number. My problem is that when I search by phone numbers I get contacts with very similar phone numbers returned, but not actually the same. Is this a bug or am I misunderstanding how the CONTAINS_TOKEN operator works?

Example:

Request Url: https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey={{apiKey}}

Request Body:

{
 "filterGroups": [
 {
 "filters": [
 {
 "propertyName": "phone",
 "operator": "CONTAINS_TOKEN",
 "value": "(443) 443-9905"
 }
 ]
 },
 {
 "filters": [
 {
 "propertyName": "phone",
 "operator": "CONTAINS_TOKEN",
 "value": "+14434439905"
 }
 ]
 }
 ],
 "properties": [
 "email",
 "firstname",
 "lastname",
 "phone"
 ]
}

Response Body:

{
 "total": 1,
 "results": [
 {
 "id": "10301",
 "properties": {
 "createdate": "2021-01-16T00:45:00.443Z",
 "email": "14433109905@hubspot.com",
 "firstname": "John",
 "hs_object_id": "10301",
 "lastmodifieddate": "2021-01-21T15:48:10.438Z",
 "lastname": "Smith",
 "phone": "443-310-9905"
 },
 "createdAt": "2021-01-16T00:45:00.443Z",
 "updatedAt": "2021-01-21T15:48:10.438Z",
 "archived": false
 }
 ]
}

So, when searching for a phone number ((443) 443-9905) with CONTAINS_TOKEN operator, I am returned a contact with this phone number (443-310-9905) instead when I believe it shouldn’t return anything.

Is this a bug or am I misunderstanding how it should work? How does it actually work?

Thank you

Hello @jndinh

Apologies for delayed response :sweat_smile:

Are you still working on this? @himanshurauthan , have you experienced this?

Hello @dennisedson I am still working on this!

Yes Dennis, so @jndinh, if you want to search contacts based on the phone number you might use the query way.

curl https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey=YOUR_HUBSPOT_API_KEY \
 --request POST \
 --header "Content-Type: application/json" \
 --data '{
 "query": "x"
 }'

The phone is a default searchable property among others, you can find more about it here.

Regards,

Himanshu Rauthan

P.S.: If this reply solves your problem. Please mark it as a solution. :folded_hands:

Hi @himanshurauthan.. this does not solve the problem nor answer my questions.

Request Url: https://api.hubapi.com/crm/v3/objects/contacts/search?hapikey={{apiKey}}

Request Body:

{
 "query": "(443) 443-9905",
 "properties": [
 "email",
 "firstname",
 "lastname",
 "phone"
 ]
}

Response:

{
 "total": 1,
 "results": [
 {
 "id": "10301",
 "properties": {
 "createdate": "2021-01-16T00:45:00.443Z",
 "email": "14433109905@hubspot.com",
 "firstname": "John",
 "hs_object_id": "10301",
 "lastmodifieddate": "2021-01-21T15:48:10.438Z",
 "lastname": "Smith",
 "phone": "443-310-9905"
 },
 "createdAt": "2021-01-16T00:45:00.443Z",
 "updatedAt": "2021-01-21T15:48:10.438Z",
 "archived": false
 }
 ]
}

(443) 443-9905 != 443-310-9905

Please advise.

Hi @jndinh,

Apologies :sweat_smile:, I suggested the solution instead of answering your question!

Here is the answer to your questions -

No this is not a bug, and this is how I found this token search working -

  • If there are duplicate tokens in the search, they will be considered as one, so in our case 443 is duplicate, so it will not search for 2 occurrences of 443, instead, anyone 443 in the search will be considered as a match.
  • Special characters are escaped from the search so if you are searching for (443) you can get the results from $443! to
  • Except * all other special characters are considered as separator and escaped from the search, so you can get the same results from - (443!9905

Hope this helps,
Himanshu

Hi @himanshurauthan. Interesting.. I’ll keep that in mind for edge cases like these then since duplicate numbers can happen in phone numbers. Thank you for the explaination!