How to Deduplicate Contacts in HubSpot Using Custom Code?
Utilize HubSpot Custom Code in Workflows to Deduplicate Contacts
As a Marketing Operations professional, one of the persistent challenges I face is dealing with bad data—missing data, incorrect data, and duplicates.
In this post, I’ll share how I used HubSpot Custom Code to effectively deduplicate contacts, streamlining our data management process.
Step 1 - Navigation
On the HubSpot Workflows page, click on "Create Workflow." You will be presented with two options: "Start from scratch" or "Use a template."
Select the second option, "Use a template," as shown in the screenshot below.
You will now be redirected to a page displaying all the available templates.
Under the “Data Cleanup” menu, you will find a template designed to merge duplicate contacts that share the same phone number. In this case, the unique identifier used is the "Phone Number."
Use this workflow template to dedupe your HubSpot contacts that share common phone number.
Step 2 - Workflow Creation
When you click on “Use template”, it will create a workflow something like below.
Now you have the workflow but you need to create a “Private app” and add that API key to the custom code to make this workflow work.
Step 3 - Adding API Key to Workflow Custom Code
I've included a video link below to help you create a Private app.
Select read and write permissions for the contacts object in the “scope” section.
Once the Private app is created, copy “Access Token” and add it to the custom code section (under Secrets) of the workflow and give it a name.
I am assuming the name of the secret key as “SECRET”
Now we need to add it to the code and make it work.
I am adding a screenshot and highlighted the line that got changed
That’s it. Turn on the workflow and it will dedupe the contacts that share the same phone number.
Note - If there are more than 2 contacts that share common phone number, this code will throw an error.
We can also modify this code to dedupe based on other properties.
I hope this post helps you automate your contact deduplication tasks in HubSpot. If you have any questions or need further assistance, feel free to leave a comment or reach out to me directly. Stay tuned for my next post where I’ll cover handling missing and incorrect data.