Automate Lead Enrichment and CRM Routing with n8n

Learn how to build an n8n workflow that enriches incoming leads, removes duplicates, scores prospects, and routes qualified contacts into your CRM automatically.

Overview

In this tutorial you’ll build a complete, real-world n8n workflow that enriches incoming leads, deduplicates and scores them, then routes qualified contacts into a CRM (HubSpot or Salesforce). This hands-on guide covers the Webhook entry point, enrichment using an external API (e.g., Clearbit), deduplication, conditional routing, and best practices for security and error handling.

Target audience: beginners who know basic n8n concepts and want a practical automation for CRM lead handling.

What you’ll build

  • A public Webhook to receive lead data (form submissions, Zapier, or your app).
  • An HTTP Request node to enrich leads via Clearbit or a similar service.
  • A lookup step to check for duplicate leads in your CRM.
  • A scoring step that tags leads as “qualified” or “nurture”.
  • A branch that creates/updates records in your CRM and notifies the sales team.
  • Prerequisites

  • An n8n instance (cloud or self-hosted).
  • API key for an enrichment provider (Clearbit, Hunter, or People Data Labs).
  • CRM API access (HubSpot, Salesforce, or your choice).
  • Basic familiarity with n8n nodes: Webhook, HTTP Request, Set, Function, IF, and the CRM node or HTTP Request to CRM.
  • Workflow diagram (conceptual)

    1. Webhook (receive lead)
    2. Set / Parse (standardize fields)
    3. HTTP Request (enrichment API)
    4. Function / Set (score & map)
    5. CRM Lookup (check duplicate)
    6. IF (qualified?)
    – Yes → CRM Create/Update, Slack/Email notify
    – No → Add to nurture list, store in DB
    7. Error handling / Logging

    Step-by-step implementation

    1) Create the Webhook node

  • Add a Webhook node and choose POST.
  • Set the path to something like `/lead-webhook`.
  • Save and activate to get the webhook URL.
  • This will accept JSON like:

    json
    {
    "email": "jane@example.com",
    "firstName": "Jane",
    "lastName": "Doe",
    "source": "landing-page",
    "utm_campaign": "spring-2025"
    }

    2) Parse and normalize incoming data

    Use a Set node to map incoming fields to a consistent schema. Example fields: `email`, `fullName`, `source`, `rawPayload`.

    3) Call the enrichment API (HTTP Request node)

    Add an HTTP Request node to call Clearbit (example) to append job title, company, location.

  • Method: GET
  • URL: `https://person.clearbit.com/v2/people/find?email={{ $json[“email”] }}`
  • Authentication: Header `Authorization: Bearer YOUR_CLEABIT_KEY`
  • Example HTTP Request node configuration (in n8n syntax):

    http
    GET https://person.clearbit.com/v2/people/find?email={{ $json.email }}
    Headers:
    Authorization: Bearer {{ $credentials.clearbitApiKey }}

    Clearbit returns structured JSON like company name, role, social profiles. Use a Set node to merge these fields back into your item.

    4) Score the lead (Function node)

    Add a Function node to compute a simple score. Example JS in Function node:

    javascript
    const emailDomain = items[0].json.email.split('@')[1] || '';
    const companySize = items[0].json.company && items[0].json.company.metrics ? items[0].json.company.metrics.employees : 0;
    let score = 0;
    if (companySize > 50) score += 40;
    if (items[0].json.title && /CEO|Founder|CTO|VP|Director/i.test(items[0].json.title)) score += 40;
    if (emailDomain.endsWith('gmail.com')) score -= 10;
    return [{ json: { ...items[0].json, leadScore: score } }];

    Adjust scoring rules to match your business logic.

    5) Check for duplicates in CRM

    Use your CRM node (e.g., HubSpot -> “Find Contact”) or an HTTP Request to query the CRM by email.

    If found, return the CRM ID so you can update; otherwise, create a new contact.

    6) Conditional routing (IF node)

    Add an IF node to check `leadScore >= 60` and `hasCompany`. Branch:

  • True: Create or Update CRM contact, add to “Hot Leads” pipeline, send Slack/Email notification.
  • False: Add to nurture sequence (Mailing list or CRM lifecycle stage) and log in your database.
  • 7) Create/Update CRM record

    Use the CRM node to create or update contact. Map enriched fields (title, company, phone, linkedin) to CRM properties. If updating, include the ID from the lookup step.

    8) Notifications and follow-up

    Add a Slack or Email node to notify the sales rep with lead details and a link to the CRM record.

    9) Error handling and retries

  • Use the Error Trigger node in n8n to capture failed runs.
  • Wrap critical HTTP calls with retry logic and check HTTP statuses.
  • Log errors to a monitoring channel or a dedicated Google Sheet.
  • Code examples

    Sample mapping in a Set node (expressed in n8n expressions):

  • `firstName`: `{{$json[“firstName”]}}`
  • `lastName`: `{{$json[“lastName”]}}`
  • `title`: `{{$json[“enrichment”][“title”]}}`
  • `company`: `{{$json[“enrichment”][“company”][“name”]}}`
  • Function node example shown above demonstrates basic scoring logic.

    Best practices

  • Use encrypted credentials in n8n for API keys.
  • Rate-limit enrichment calls (batch or queue) to avoid hitting provider limits.
  • Validate email format before enrichment to save API credits.
  • Log both successful and failed runs for auditing.
  • Avoid storing PII in plain logs; adhere to GDPR and privacy laws.
  • Testing and rollout

    1. Test with a few sample payloads via the webhook URL (curl or Postman).
    2. Check each node’s output in n8n execution preview.
    3. Run load tests with realistic volumes to detect rate limits and latency.
    4. Switch webhook to production and monitor for errors for 48–72 hours.

    Conclusion and next steps

    You now have a reusable n8n workflow pattern: webhook → enrichment → deduplication → scoring → CRM routing. This pattern scales to other enrichment providers, CRMs, and follow-up automations (SMS, drip campaigns, SDR assignments).

    Next steps:

  • Add advanced scoring using historical conversion data.
  • Integrate a queue or rate-limiter for high-volume lead ingestion.
  • Add A/B rules to route leads to different sales teams based on territory or ARR.

Good luck — build iteratively, monitor closely, and refine scoring with real outcomes to improve your automation’s ROI.

Related Posts