{
  "name": "Lead Routing Starter Template",
  "nodes": [
    {
      "id": "webhook-1",
      "name": "Form Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [200, 300],
      "parameters": {
        "path": "your-webhook-path",
        "httpMethod": "POST",
        "responseMode": "lastNode",
        "options": {}
      }
    },
    {
      "id": "code-1",
      "name": "Extract Lead Data",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [420, 300],
      "parameters": {
        "jsCode": "// Extract lead data from your form submission\n// Adjust field names to match your form builder's payload\nconst body = $input.first().json.body || $input.first().json;\nconst data = body.data || body;\n\n// Map your form fields here\nconst firstName = data.firstName || data.first_name || '';\nconst lastName = data.lastName || data.last_name || '';\nconst email = data.email || '';\nconst phone = data.phone || '';\nconst company = data.company || data.company_name || 'Unknown';\nconst message = data.message || data.comments || '';\n\n// Simple lead scoring based on form data\nlet score = 0;\nif (company && company !== 'Unknown') score += 2;\nif (message && message.length > 50) score += 2;\nif (phone) score += 1;\n\nconst qualified = score >= 3;\n\nreturn [{ json: {\n  firstName,\n  lastName,\n  email,\n  phone,\n  company,\n  message,\n  score,\n  qualified,\n  source: 'Website Form'\n} }];"
      }
    },
    {
      "id": "http-1",
      "name": "Create CRM Contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [640, 200],
      "parameters": {
        "method": "POST",
        "url": "https://YOUR_CRM_DOMAIN/api/contacts",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_CRM_API_KEY"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ name: $json.firstName + ' ' + $json.lastName, email: $json.email, company: $json.company, phone: $json.phone }) }}"
      }
    },
    {
      "id": "if-qualified",
      "name": "Lead Qualified?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [640, 400],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $('Extract Lead Data').first().json.qualified }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true"
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "http-2",
      "name": "Add to Email List",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [860, 400],
      "parameters": {
        "method": "POST",
        "url": "https://YOUR_EMAIL_PLATFORM/api/subscribers",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "YOUR_EMAIL_API_KEY"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ email: $('Extract Lead Data').first().json.email, name: $('Extract Lead Data').first().json.firstName + ' ' + $('Extract Lead Data').first().json.lastName, lists: [1], status: 'enabled' }) }}"
      }
    },
    {
      "id": "gmail-1",
      "name": "Notify Sales Team",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [1080, 300],
      "parameters": {
        "sendTo": "your-email@example.com",
        "subject": "={{ 'New Lead: ' + $('Extract Lead Data').first().json.firstName + ' ' + $('Extract Lead Data').first().json.lastName + ' (' + $('Extract Lead Data').first().json.company + ') - Score: ' + $('Extract Lead Data').first().json.score }}",
        "message": "={{ '<h3>New Lead Submission</h3>' + '<p><strong>Name:</strong> ' + $('Extract Lead Data').first().json.firstName + ' ' + $('Extract Lead Data').first().json.lastName + '</p>' + '<p><strong>Email:</strong> ' + $('Extract Lead Data').first().json.email + '</p>' + '<p><strong>Company:</strong> ' + $('Extract Lead Data').first().json.company + '</p>' + '<p><strong>Phone:</strong> ' + $('Extract Lead Data').first().json.phone + '</p>' + '<p><strong>Message:</strong> ' + $('Extract Lead Data').first().json.message + '</p>' + '<p><strong>Lead Score:</strong> ' + $('Extract Lead Data').first().json.score + '/5</p>' + '<p><strong>Qualified:</strong> ' + ($('Extract Lead Data').first().json.qualified ? 'Yes' : 'No') + '</p>' }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Form Webhook": {
      "main": [
        [
          {
            "node": "Extract Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Lead Data": {
      "main": [
        [
          {
            "node": "Create CRM Contact",
            "type": "main",
            "index": 0
          },
          {
            "node": "Lead Qualified?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create CRM Contact": {
      "main": [
        [
          {
            "node": "Notify Sales Team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Qualified?": {
      "main": [
        [
          {
            "node": "Add to Email List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add to Email List": {
      "main": [
        [
          {
            "node": "Notify Sales Team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Starter template for routing form submissions to your CRM and email platform. Import into n8n, then update the placeholder URLs and API keys with your own credentials.\n\nFlow: Form webhook -> Extract & score lead -> Create CRM contact + Check qualification -> Add qualified leads to email list -> Notify your team.\n\nFrom: https://whtnxt.io/blog/n8n-marketing-automation-engine"
  }
}
