Here's an advanced n8n workflow that demonstrates multiple sophisticated automation patterns. This workflow processes customer data through validation, enrichment, scoring, and routing:
{
"name": "Advanced Customer Data Processing Pipeline",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "customer-intake",
"responseMode": "responseNode",
"options": {}
},
"id": "webhook-trigger",
"name": "Customer Data Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [240, 300],
"webhookId": "customer-data-intake"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"leftValue": "={{ $json.email }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
},
{
"leftValue": "={{ $json.company }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "data-validation",
"name": "Validate Required Fields",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [460, 300]
},
{
"parameters": {
"jsCode": "// Clean and standardize the customer data\nconst items = $input.all();\n\nreturn items.map(item => {\n const data = item.json;\n \n // Clean email and convert to lowercase\n const cleanEmail = data.email?.toLowerCase().trim();\n \n // Standardize phone number (remove non-digits)\n const cleanPhone = data.phone?.replace(/\\D/g, '') || '';\n \n // Clean company name\n const cleanCompany = data.company?.trim().replace(/\\s+/g, ' ');\n \n // Generate customer ID\n const customerId = `CUST_${Date.now()}_${Math.random().toString(36).substr(2, 5).toUpperCase()}`;\n \n // Calculate data completeness score\n const fields = ['email', 'company', 'phone', 'website', 'industry'];\n const completedFields = fields.filter(field => data[field] && data[field].trim() !== '').length;\n const completenessScore = Math.round((completedFields / fields.length) * 100);\n \n return {\n json: {\n customerId,\n originalData: data,\n email: cleanEmail,\n company: cleanCompany,\n phone: cleanPhone,\n website: data.website?.trim(),\n industry: data.industry?.trim(),\n completenessScore,\n processedAt: new Date().toISOString(),\n source: 'webhook_intake'\n }\n };\n});"
},
"id": "data-cleaning",
"name": "Clean & Standardize Data",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [680, 200]
},
{
"parameters": {
"url": "https://api.clearbit.com/v2/companies/find",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "clearbitApi",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "domain",
"value": "={{ $json.website || $json.email.split('@')[1] }}"
}
]
},
"options": {
"redirect": {
"redirect": {}
},
"response": {
"response": {
"responseFormat": "json"
}
},
"timeout": 10000
}
},
"id": "company-enrichment",
"name": "Enrich Company Data",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [900, 200],
"continueOnFail": true
},
{
"parameters": {
"jsCode": "// Merge original data with enrichment data\nconst items = $input.all();\nconst enrichmentData = $('Enrich Company Data').all();\n\nreturn items.map((item, index) => {\n const originalData = item.json;\n const enrichment = enrichmentData[index]?.json || {};\n \n // Calculate lead score based on various factors\n let leadScore = 0;\n \n // Company size scoring\n if (enrichment.employees) {\n if (enrichment.employees > 1000) leadScore += 30;\n else if (enrichment.employees > 100) leadScore += 20;\n else if (enrichment.employees > 10) leadScore += 10;\n }\n \n // Industry scoring\n const highValueIndustries = ['technology', 'finance', 'healthcare', 'manufacturing'];\n if (enrichment.category?.industry && highValueIndustries.includes(enrichment.category.industry.toLowerCase())) {\n leadScore += 25;\n }\n \n // Data completeness scoring\n leadScore += Math.round(originalData.completenessScore * 0.2);\n \n // Funding/Revenue scoring\n if (enrichment.metrics?.annualRevenue) {\n if (enrichment.metrics.annualRevenue > 10000000) leadScore += 20;\n else if (enrichment.metrics.annualRevenue > 1000000) leadScore += 15;\n else if (enrichment.metrics.annualRevenue > 100000) leadScore += 10;\n }\n \n // Technology stack scoring (if available)\n if (enrichment.tech && enrichment.tech.length > 5) {\n leadScore += 15;\n }\n \n // Determine lead tier\n let leadTier;\n if (leadScore >= 70) leadTier = 'HOT';\n else if (leadScore >= 40) leadTier = 'WARM';\n else leadTier = 'COLD';\n \n return {\n json: {\n ...originalData,\n enrichment: {\n companyName: enrichment.name || originalData.company,\n employees: enrichment.employees,\n industry: enrichment.category?.industry,\n location: enrichment.geo?.city + ', ' + enrichment.geo?.country,\n annualRevenue: enrichment.metrics?.annualRevenue,\n technologies: enrichment.tech || [],\n foundedYear: enrichment.foundedYear,\n description: enrichment.description\n },\n scoring: {\n leadScore,\n leadTier,\n scoringFactors: {\n companySize: enrichment.employees || 'unknown',\n industry: enrichment.category?.industry || 'unknown',\n revenue: enrichment.metrics?.annualRevenue || 'unknown',\n dataCompleteness: originalData.completenessScore\n }\n },\n enrichedAt: new Date().toISOString()\n }\n };\n});"
},
"id": "lead-scoring",
"name": "Calculate Lead Score",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [1120, 200]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"leftValue": "={{ $json.scoring.leadTier }}",
"rightValue": "HOT",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "hot-lead-filter",
"name": "Hot Lead Router",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [1340, 200]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"leftValue": "={{ $json.scoring.leadTier }}",
"rightValue": "WARM",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "warm-lead-filter",
"name": "Warm Lead Router",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [1340, 400]
},
{
"parameters": {
"url": "https://api.hubspot.com/crm/v3/objects/contacts",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "hubspotApi",
"sendBody": true,
"specifyBodyType": "json",
"jsonBody": "={\n \"properties\": {\n \"email\": \"{{ $json.email }}\",\n \"firstname\": \"{{ $json.originalData.firstName || '' }}\",\n \"lastname\": \"{{ $json.originalData.lastName || '' }}\",\n \"company\": \"{{ $json.enrichment.companyName }}\",\n \"phone\": \"{{ $json.phone }}\",\n \"website\": \"{{ $json.website }}\",\n \"industry\": \"{{ $json.enrichment.industry }}\",\n \"hs_lead_status\": \"{{ $json.scoring.leadTier }}\",\n \"custom_lead_score\": \"{{ $json.scoring.leadScore }}\",\n \"data_source\": \"n8n_automation\"\n }\n}",
"options": {
"response": {
"response": {
"responseFormat": "json"
}
}
}
},
"id": "create-hubspot-contact",
"name": "Create HubSpot Contact",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [1560, 100],
"continueOnFail": true
},
{
"parameters": {
"url": "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK",
"sendBody": true,
"specifyBodyType": "json",
"jsonBody": "={\n \"text\": \"🔥 Hot Lead Alert!\",\n \"attachments\": [\n {\n \"color\": \"danger\",\n \"fields\": [\n {\n \"title\": \"Company\",\n \"value\": \"{{ $json.enrichment.companyName }}\",\n \"short\": true\n },\n {\n \"title\": \"Email\",\n \"value\": \"{{ $json.email }}\",\n \"short\": true\n },\n {\n \"title\": \"Lead Score\",\n \"value\": \"{{ $json.scoring.leadScore }}/100\",\n \"short\": true\n },\n {\n \"title\": \"Industry\",\n \"value\": \"{{ $json.enrichment.industry || 'Unknown' }}\",\n \"short\": true\n },\n {\n \"title\": \"Employees\",\n \"value\": \"{{ $json.enrichment.employees || 'Unknown' }}\",\n \"short\": true\n },\n {\n \"title\": \"Revenue\",\n \"value\": \"${{ ($json.enrichment.annualRevenue || 0).toLocaleString() }}\",\n \"short\": true\n }\n ]\n }\n ]\n}"
},
"id": "slack-hot-alert",
"name": "Slack Hot Lead Alert",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [1560, 200]
},
{
"parameters": {
"url": "https://api.airtable.com/v0/YOUR_BASE_ID/Leads",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "airtableTokenApi",
"sendBody": true,
"specifyBodyType": "json",
"jsonBody": "={\n \"fields\": {\n \"Customer ID\": \"{{ $json.customerId }}\",\n \"Email\": \"{{ $json.email }}\",\n \"Company\": \"{{ $json.enrichment.companyName }}\",\n \"Phone\": \"{{ $json.phone }}\",\n \"Website\": \"{{ $json.website }}\",\n \"Industry\": \"{{ $json.enrichment.industry }}\",\n \"Lead Score\": {{ $json.scoring.leadScore }},\n \"Lead Tier\": \"{{ $json.scoring.leadTier }}\",\n \"Employees\": {{ $json.enrichment.employees || 0 }},\n \"Annual Revenue\": {{ $json.enrichment.annualRevenue || 0 }},\n \"Location\": \"{{ $json.enrichment.location }}\",\n \"Data Completeness\": {{ $json.completenessScore }},\n \"Source\": \"{{ $json.source }}\",\n \"Created At\": \"{{ $json.processedAt }}\"\n }\n}"
},
"id": "save-to-airtable",
"name": "Save to Airtable",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [1560, 400]
},
{
"parameters": {
"url": "https://api.mailchimp.com/3.0/lists/YOUR_LIST_ID/members",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "mailchimpApi",
"sendBody": true,
"specifyBodyType": "json",
"jsonBody": "={\n \"email_address\": \"{{ $json.email }}\",\n \"status\": \"subscribed\",\n \"merge_fields\": {\n \"FNAME\": \"{{ $json.originalData.firstName || '' }}\",\n \"LNAME\": \"{{ $json.originalData.lastName || '' }}\",\n \"COMPANY\": \"{{ $json.enrichment.companyName }}\",\n \"INDUSTRY\": \"{{ $json.enrichment.industry }}\"\n },\n \"tags\": [\"{{ $json.scoring.leadTier }}_LEAD\", \"AUTOMATED_IMPORT\"]\n}"
},
"id": "add-to-mailchimp",
"name": "Add to MailChimp",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [1560, 500]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "={\n \"success\": true,\n \"customerId\": \"{{ $json.customerId }}\",\n \"leadScore\": {{ $json.scoring.leadScore }},\n \"leadTier\": \"{{ $json.scoring.leadTier }}\",\n \"message\": \"Customer data processed successfully\",\n \"processedAt\": \"{{ $json.processedAt }}\"\n}"
},
"id": "webhook-response",
"name": "Success Response",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [1780, 300]
},
{
"parameters": {
"respondWith": "json",
"responseBody": "{\n \"success\": false,\n \"error\": \"Missing required fields: email and company are required\",\n \"receivedData\": \"{{ $json }}\"\n}",
"options": {
"responseCode": 400
}
},
"id": "validation-error-response",
"name": "Validation Error Response",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [680, 400]
},
{
"parameters": {
"jsCode": "// Error handling and logging\nconst items = $input.all();\nconst errorNode = $('Enrich Company Data').first();\n\nreturn items.map(item => {\n return {\n json: {\n ...item.json,\n enrichment: {\n companyName: item.json.company,\n employees: null,\n industry: null,\n location: 'Unknown',\n annualRevenue: null,\n technologies: [],\n foundedYear: null,\n description: 'Enrichment failed - proceeding with basic data'\n },\n enrichmentError: true,\n errorDetails: 'Company enrichment API failed or returned no data'\n }\n };\n});"
},
"id": "enrichment-fallback",
"name": "Enrichment Fallback",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [900, 300]
}
],
"connections": {
"Customer Data Webhook": {
"main": [
[
{
"node": "Validate Required Fields",
"type": "main",
"index": 0
}
]
]
},
"Validate Required Fields": {
"main": [
[
{
"node": "Clean & Standardize Data",
"type": "main",
"index": 0
}
],
[
{
"node": "Validation Error Response",
"type": "main",
"index": 0
}
]
]
},
"Clean & Standardize Data": {
"main": [
[
{
"node": "Enrich Company Data",
"type": "main",
"index": 0
}
]
]
},
"Enrich Company Data": {
"main": [
[
{
"node": "Calculate Lead Score",
"type": "main",
"index": 0
}
],
[
{
"node": "Enrichment Fallback",
"type": "main",
"index": 0
}
]
]
},
"Enrichment Fallback": {
"main": [
[
{
"node": "Calculate Lead Score",
"type": "main",
"index": 0
}
]
]
},
"Calculate Lead Score": {
"main": [
[
{
"node": "Hot Lead Router",
"type": "main",
"index": 0
},
{
"node": "Warm Lead Router",
"type": "main",
"index": 0
},
{
"node": "Save to Airtable",
"type": "main",
"index": 0
}
]
]
},
"Hot Lead Router": {
"main": [
[
{
"node": "Create HubSpot Contact",
"type": "main",
"index": 0
},
{
"node": "Slack Hot Lead Alert",
"type": "main",
"index": 0
}
]
]
},
"Warm Lead Router": {
"main": [
[
{
"node": "Add to MailChimp",
"type": "main",
"index": 0
}
]
]
},
"Create HubSpot Contact": {
"main": [
[
{
"node": "Success Response",
"type": "main",
"index": 0
}
]
]
},
"Slack Hot Lead Alert": {
"main": [
[
{
"node": "Success Response",
"type": "main",
"index": 0
}
]
]
},
"Save to Airtable": {
"main": [
[
{
"node": "Success Response",
"type": "main",
"index": 0
}
]
]
},
"Add to MailChimp": {
"main": [
[
{
"node": "Success Response",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"tags": [],
"triggerCount": 1,
"updatedAt": "2025-06-16T10:00:00.000Z",
"versionId": "1"
}
This advanced workflow includes:
Key Features:
- Webhook trigger for receiving customer data
- Data validation with proper error handling
- Data cleaning and standardization using JavaScript
- External API integration for company enrichment (Clearbit)
- Advanced lead scoring algorithm with multiple factors
- Conditional routing based on lead quality
- Multiple integrations (HubSpot, Slack, Airtable, MailChimp)
- Error handling and fallbacks for API failures
- Comprehensive data transformation and enrichment
Workflow Process:
- Receives customer data via webhook
- Validates required fields
- Cleans and standardizes the data
- Enriches with external company data
- Calculates lead scores based on multiple factors
- Routes leads to different destinations based on score
- Sends hot leads to sales team via Slack
- Creates contacts in HubSpot for hot leads
- Adds warm leads to email marketing
- Stores all leads in Airtable for tracking
To use this workflow:
- Save the JSON to a file (e.g.,
advanced-customer-workflow.json)
- Import it into your n8n instance
- Configure the API credentials for each service
- Update webhook URLs and API endpoints
- Test with sample data
The workflow demonstrates advanced n8n concepts like error handling, data transformation, conditional logic, and multi-service integration.