Home/Resources/Automations/Automatically Merge Duplicate HubSpot Contacts (Video + n8n Workflow)
Resources · Automations · n8n FREE · 2026

Automatically Merge Duplicate HubSpot Contacts (Video + n8n Workflow)

Want to merge duplicate contacts in HubSpot without paying for advanced features? This n8n automation is built to save you time by automatically handling contact merges via the HubSpot API.

Get it free

The full automation, in your inbox

No spam · Unsubscribe anytime
Overview · 10 steps

Automatically Merge Duplicate HubSpot Contacts (Video + n8n Workflow)

Automatically Merge Duplicate HubSpot Contacts (CRM) (Free n8n Workflow + Video + Downloadable Guide)

Before you start

Prerequisite: Define a Unique Criteria to Identify Duplicate Contacts in HubSpot

  1. !
    You'll need

    Prerequisite: Define a Unique Criteria to Identify Duplicate Contacts in HubSpot

    • A self-hosted n8n instance with terminal access.
    • API credentials for the services used in this workflow.
Get it free

The full automation, in your inbox

No spam · Unsubscribe anytime
Step 01 → 10

n8n workflow breakdown.

10 steps, 0 lines of code. Here is exactly what runs under the hood.
  1. 01
    Step 01

    Start the Workflow (Manual Trigger).

    This first step lets you manually test the workflow. Using n8n’s Manual Trigger module, you can run the scenario on demand to verify that everything works before automating it in production.

    The manual trigger is especially useful for testing each step in real-time and diagnosing any issues. Once your tests are validated, you can replace this trigger with an automated one (e.g., cron, webhook…) if needed.

    To start: click "Execute Workflow" in n8n to begin the process.

    Start the Workflow
    Settings
    • Trigger type: Manual Trigger
    • Use case: Launch the workflow manually via the n8n interface
  2. 02
    Step 02

    Retrieve All Contacts from HubSpot.

    This step uses the HubSpot module to fetch all contacts stored in your CRM. The goal is to build a full dataset to analyze and detect duplicates based on your chosen unique identifier (e.g., LinkedIn Profile ID).

    We use the Get All option to retrieve all records at once, allowing you to process every contact automatically without any specific limit.

    This step allows you to centralize all contact records so they can be processed one by one in the next steps.

    Retrieve All Contacts from HubSpot
    Settings
    • Resource: Contact
    • Operation: Get All
    • Return All: Enabled (Yes)
    • Retrieved properties: linkedin_profile_id (you can add more fields if needed)
  3. 03
    Step 03

    Loop Through Each Contact (SplitInBatches).

    This step uses the SplitInBatches module to process each contact one by one. It helps prevent API overload and gives you precise control over individual contact handling.

    The batch is configured with a size of 1, meaning each workflow execution processes a single contact before moving on to the next.

    This setup ensures smooth and safe execution even when dealing with a large volume of contacts.

    Loop Through Each Contact
    Settings
    • Batch Size: 1
  4. 04
    Step 04

    Add a 1-Second Delay (Rate Limiting).

    To avoid API overload and comply with HubSpot rate limits, this step uses a Wait module to insert a 1-second delay between each contact processing.

    This step is essential if you're handling a high volume of contacts—it prevents errors like "429 Too Many Requests" during consecutive HubSpot API calls.

    Thanks to this short pause, the workflow remains stable and API-compliant, even when running across hundreds or thousands of contacts.

    Add a 1-Second Delay
    Settings
    • Wait Time: 1 second
  5. 05
    Step 05

    Check for LinkedIn Profile ID.

    This step is crucial: it uses an IF module to verify whether the current contact has a LinkedIn Profile ID. This field is essential for accurately detecting duplicates.

    If the contact doesn’t have this field filled in, the workflow skips it and moves to the next one, avoiding errors or unnecessary lookups.

    This step helps secure the workflow by ensuring that only eligible contacts (those with a LinkedIn ID) are analyzed.

    Check for LinkedIn Profile ID
    Settings
    • Condition: {{$('Loop Contacts One by One').item.json.properties.linkedin_profile_id.value}} is not empty
    • Combinator: AND
  6. 06
    Step 06

    Search for Contacts by LinkedIn Profile ID (HubSpot Search).

    This step is essential: it identifies all duplicate contacts based on their LinkedIn Profile ID. To do this, we use the native HubSpot – Search module, which allows you to search contacts by a custom property.

    Why this approach? Unlike company searches that require a custom API call, here we can use the native n8n module directly, as it supports searching contacts by custom property.

    The module queries the HubSpot API using the internal endpoint and limits the results to 2, which is enough to confirm a duplicate.

    {
      "propertyName": "linkedin_profile_id|number",
      "value": "={{ $('Loop Contacts One by One').item.json.properties.linkedin_profile_id.value }}"
    }
    

    This query searches for all contacts whose LinkedIn Profile ID matches the one from the current contact being processed. The response includes the key data of the contact to be merged.

    Why a limit of 2? This checks whether there are at least two contacts with the same LinkedIn Profile ID. If that’s the case, a duplicate is detected and the workflow proceeds to the next step to merge them.

    Search for Contacts by LinkedIn Profile
    Settings
    • Resource: Contact
    • Operation: Search
    • Limit: 2
    • Filter Groups:
  7. 07
    Step 07

    Process Search Results (Extract Contact IDs).

    This step uses a Code module to analyze the results returned by the HubSpot search. Its role is twofold: count the number of results and extract the IDs of the contacts to be merged.

    The code checks whether at least 2 contacts were found. If so, it extracts:

    • primaryObjectId: the ID of the first contact (to be kept after the merge)
    • objectIdToMerge: the ID of the second contact (to be merged and removed)

    This code also adds a safeguard: if fewer than 2 contacts are found, it returns an info message stating that no merge will be performed in this cycle.

    This step prepares all the necessary data for the final merge API call.

    Process Search Results
    Code used
    • const items = $input.all();
      
      if (items.length < 2) {
        return [
          {
            json: {
              hubspotResults: items.length,
              message: 'Not enough contacts to merge'
            }
          }
        ];
      }
      
      const primary = items[0];
      const secondary = items[1];
      
      return [
        {
          json: {
            hubspotResults: items.length,
            primaryObjectId: primary.json.id,
            objectIdToMerge: secondary.json.id
          }
        }
      ];
  8. 08
    Step 08

    Check If Duplicates Exist (Results ≤ 1).

    This step uses an IF module to check the number of results found during the duplicate search. The goal is to confirm whether at least two contacts exist with the same LinkedIn Profile ID.

    If the number of results is less than or equal to 1, it means no duplicate was detected, and the workflow automatically moves on to the next contact without attempting a merge.

    This step helps avoid unnecessary API calls when the search results include only one contact (or none), ensuring better performance and improved reliability.

    Check If Duplicates Exist
    Settings
    • Condition: {{$json.hubspotResults}} ≤ 1
    • Case Sensitive: Yes
    • Combinator: AND
  9. 09
    Step 09

    Ensure IDs Are Different (Prevent Incorrect Merges).

    This step uses an IF module to make sure that the two contacts to be merged have different IDs. This is a critical safeguard—HubSpot does not allow merging a contact with itself, and skipping this check could trigger an error.

    This condition prevents unnecessary API errors by blocking the merge attempt if primaryObjectId and objectIdToMerge are the same.

    This step helps fully secure the process before the final API call is made.

    Ensure IDs Are Different
    Settings
    • Condition: {{$json.primaryObjectId}} ≠ {{$json.objectIdToMerge}}
    • Case Sensitive: Yes
    • Combinator: AND
  10. 10
    Step 10

    Merge Duplicate Contacts (HubSpot API).

    This final step uses an HTTP Request module to send a POST request to the HubSpot API in order to merge the two contacts identified as duplicates.

    The API call uses the official endpoint: https://api.hubapi.com/crm/v3/objects/contacts/merge to perform the merge, authenticated via your HubSpot token.

    {
      "primaryObjectId": "{{ $json.primaryObjectId }}",
      "objectIdToMerge": "{{ $json.objectIdToMerge }}"
    }
    

    This request merges the secondary contact (objectIdToMerge) into the primary contact (primaryObjectId). HubSpot keeps the main data from the primary contact and archives the duplicate.

    This step completes the automation—leaving your CRM clean, duplicate-free, and ready for use. If you need help implementing similar CRM automation workflows, our team can support your specific needs.

    Settings
    • Method: POST
    • URL: https://api.hubapi.com/crm/v3/objects/contacts/merge
    • Headers: Content-Type: application/json + Authorization: Bearer Token
    • Body:
You've seen the full workflow

Get the ready-to-import n8n JSON plus the install guide

Drop your email and we'll send you the complete scenario.

  • n8n JSON ready to import
  • Written setup guide
  • Video tutorial included
2,400+ makers downloaded this workflow this month.
Why this matters

Why Removing Duplicate HubSpot Contacts Is Essential for Your CRM

Keeping a clean and well-organized HubSpot CRM is crucial to ensure data quality and maximize the efficiency of your sales and marketing teams. Duplicate contacts cause errors, skew reports, and make customer relationships harder to manage. Problems caused by duplicates: Inaccurate or conflicting data in your pipelines. Risk of contacting the same client or lead multiple times. Less effective marketing campaigns due to segmentation errors. Wasted time for your teams manually checking and fixing records. Benefits of automatically merging duplicates in HubSpot: Centralized key information for each contact. Better customer experience with accurate, up-to-date data. Automated repetitive tasks to boost productivity. Reliable reports and insights to guide your sales strategy. By automating the merging of duplicate contacts in HubSpot, you ensure a high-performing CRM, save valuable time, and reduce the risk of human error. This automation is a powerful lever to improve your customer database management and accelerate your company’s growth. Looking for similar automation for companies? Check out our guide to merge duplicate companies in HubSpot.

Get the workflow

The full automation, in your inbox.

n8n JSON, written guide and video tutorial, everything to ship this in under 15 minutes.

  • Complete n8n scenario JSON
  • Step-by-step setup documentation
  • Full video walkthrough