{
  "name": "04 · CRM & Sales / Lead Enrichment & Router",
  "active": false,
  "nodes": [
    {
      "id": "db50d372-638c-4a8b-a1ce-4893dcc6a5d6",
      "name": "📘 Guide",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -640,
        -120
      ],
      "parameters": {
        "content": "## 04 · CRM & Sales · Lead Enrichment & Router\n\n### What this does\nEnriches inbound leads (company, size, tech), scores ICP fit, and routes to SDR queues.\n\n### Setup checklist\n1. Clearbit/Apollo/HTTP enricher\n2. CRM create/update API\n3. Scoring weights in Code\n\n### How to test locally\nPOST `crm-lead-enrich` with `{ \"email\":\"a@acme.com\", \"name\":\"Ada\" }`\n\n### Tips\n- Keep credentials in n8n Credentials (never hardcode secrets).\n- Use **Test URL** on the Webhook while developing.\n- Activate only after credentials + destinations are configured.\n",
        "width": 560,
        "height": 560,
        "color": 3
      }
    },
    {
      "id": "a50cfc36-ee43-480b-a360-89a574c176bc",
      "name": "⚙️ Config",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -640,
        480
      ],
      "parameters": {
        "content": "## Config map\n\n- **Webhook path:** `crm-lead-enrich`\n- **Replace** all `https://httpbin.org/...` calls with real integrations.\n- **Credentials:** create in n8n → Credentials, then select on HTTP nodes.\n- **Activate** workflow only after a successful Test execution.\n\n### Local files\nShared host folder is mounted at `/files` inside n8n.",
        "width": 560,
        "height": 320,
        "color": 2
      }
    },
    {
      "id": "8abb5f02-ef1b-4829-8f9f-bb253a484e4e",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        200
      ],
      "webhookId": "66f0da56-6196-4f7e-a381-c99321776994",
      "parameters": {
        "httpMethod": "POST",
        "path": "crm-lead-enrich",
        "responseMode": "responseNode",
        "options": {}
      }
    },
    {
      "id": "c0b147c4-09a2-4be8-ba14-23a6a6a92d43",
      "name": "Normalize Payload",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        280,
        200
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "receivedAt",
              "value": "={{ $now.toISO() }}",
              "type": "string"
            },
            {
              "id": "2",
              "name": "source",
              "value": "04 · CRM & Sales",
              "type": "string"
            },
            {
              "id": "3",
              "name": "workflow",
              "value": "Lead Enrichment & Router",
              "type": "string"
            },
            {
              "id": "4",
              "name": "payload",
              "value": "={{ $json.body || $json }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "8dc08821-165f-4d79-9eae-b1e5fe37fc95",
      "name": "Business Logic",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        200
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const item = $input.first().json;\nconst payload = item.payload || item;\nconst platforms = payload.platforms || ['primary', 'secondary', 'archive'];\nconst jobs = (Array.isArray(platforms) ? platforms : [platforms]).map((p, idx) => ({\n  json: {\n    ...item,\n    channel: p,\n    jobId: `${Date.now()}-${idx}`,\n    status: 'queued',\n    transformed: {\n      title: payload.title || payload.caption || payload.subject || defTitle(),\n      body: payload.body || payload.message || payload.caption || JSON.stringify(payload),\n      meta: payload.meta || {},\n    },\n  },\n}));\nreturn jobs.length ? jobs : [{ json: { ...item, channel: 'primary', status: 'queued' } }];\nfunction defTitle(){ return 'Lead Enrichment & Router'; }\n"
      }
    },
    {
      "id": "2cba123e-4063-4373-99f5-5fbbead4c6bc",
      "name": "Ready to Dispatch?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        840,
        200
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "efe408b9-0d6f-4090-bcb8-5e231fecd630",
              "leftValue": "={{ $json.status === \"queued\" }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "f199de77-7945-4f7d-9adf-2856e279be60",
      "name": "Dispatch A (replace me)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1120,
        80
      ],
      "parameters": {
        "method": "POST",
        "url": "https://httpbin.org/post",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}"
      }
    },
    {
      "id": "3318696b-2a0b-4b3b-90c1-1d098fa776c6",
      "name": "Dispatch B (replace me)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1120,
        320
      ],
      "parameters": {
        "method": "POST",
        "url": "https://httpbin.org/post",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}"
      }
    },
    {
      "id": "dd827015-8d5c-4162-a5ba-0c1953453a96",
      "name": "Aggregate Results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1400,
        200
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const items = $input.all().map(i => i.json);\nreturn [{ json: { ok: true, workflow: 'Lead Enrichment & Router', count: items.length, results: items } }];"
      }
    },
    {
      "id": "f8aad1a8-758c-4058-af47-26eb67e85542",
      "name": "Webhook Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1680,
        200
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Normalize Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Payload": {
      "main": [
        [
          {
            "node": "Business Logic",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Business Logic": {
      "main": [
        [
          {
            "node": "Ready to Dispatch?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ready to Dispatch?": {
      "main": [
        [
          {
            "node": "Dispatch A (replace me)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Dispatch B (replace me)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dispatch A (replace me)": {
      "main": [
        [
          {
            "node": "Aggregate Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Dispatch B (replace me)": {
      "main": [
        [
          {
            "node": "Aggregate Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Results": {
      "main": [
        [
          {
            "node": "Webhook Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "tags": [],
  "meta": {
    "templateCredsSetupCompleted": true,
    "description": "Enriches inbound leads (company, size, tech), scores ICP fit, and routes to SDR queues."
  },
  "pinData": {}
}