{
  "id": "CrPyRThN2WX2rP5s",
  "name": "Score B2B leads with AI from webhook or form submissions",
  "tags": [],
  "nodes": [
    {
      "id": "9ea04987-285e-450e-a8e9-d95c956ccb68",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        608,
        -128
      ],
      "parameters": {
        "color": 5,
        "width": 480,
        "height": 380,
        "content": "## Score B2B Leads with AI\n\n**Who it's for:** Sales teams, freelancers, and agencies receiving leads via webhook or contact forms.\n\n**What it does:** Receives lead data (name, email, company, website), uses OpenAI to score each lead 1\u201310 based on fit, and routes to **Hot** (\u22657 \u2192 immediate follow-up) or **Nurture** (add to sequence).\n\n**Setup:** Add your OpenAI API key via pre-configured credentials in the AI Score Lead node. No hardcoded keys. Activate the workflow and test with Manual or send a POST to the webhook URL."
      },
      "typeVersion": 1
    },
    {
      "id": "9003ee31-df43-4b1c-b2cd-3cc9dc084202",
      "name": "Sticky Note 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1152,
        -336
      ],
      "parameters": {
        "color": 7,
        "height": 140,
        "content": "**Step 1 \u2014 Triggers**\n\n\u2022 Webhook: POST to `/incoming-lead`\n\u2022 Manual: Test with sample data"
      },
      "typeVersion": 1
    },
    {
      "id": "b905b0c6-6080-43a8-98ca-25c4c9264164",
      "name": "Sticky Note 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1616,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 280,
        "height": 120,
        "content": "**Step 2\u20134 \u2014 Process**\n\nNormalize \u2192 AI Score (OpenAI) \u2192 Parse"
      },
      "typeVersion": 1
    },
    {
      "id": "017f10ca-70ab-4de5-bf26-b4597ba22e52",
      "name": "Sticky Note 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2160,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 320,
        "height": 120,
        "content": "**Step 5 \u2014 Route**\n\nHot (\u22657) \u2192 immediate follow-up  |  Nurture \u2192 add to sequence"
      },
      "typeVersion": 1
    },
    {
      "id": "51751392-d4ee-47f7-aa2a-af98b19033cd",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "position": [
        1184,
        16
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "SCORE_THRESHOLD",
              "type": "number",
              "value": 7
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "b1b1561e-d014-4939-a078-23fabac0ed36",
      "name": "Route by Source",
      "type": "n8n-nodes-base.if",
      "position": [
        1408,
        16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "caseSensitive": true
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.body !== undefined && $json.body !== null }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "c878ffac-d4a7-4f53-9f3e-9a01d6fedcee",
      "name": "Manual Test",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        1184,
        176
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "05e009ce-a50c-49a3-b229-dab5612c0e8a",
      "name": "Sample Data",
      "type": "n8n-nodes-base.set",
      "position": [
        1696,
        224
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "name",
              "type": "string",
              "value": "Marie Dupont"
            },
            {
              "id": "2",
              "name": "email",
              "type": "string",
              "value": "user@example.com"
            },
            {
              "id": "3",
              "name": "company",
              "type": "string",
              "value": "Innovate SAS"
            },
            {
              "id": "4",
              "name": "website",
              "type": "string",
              "value": "https://innovate.co"
            },
            {
              "id": "5",
              "name": "SCORE_THRESHOLD",
              "type": "number",
              "value": "={{ $json.SCORE_THRESHOLD ?? 7 }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e134a073-3ab5-4ce1-9043-b93238cd7c10",
      "name": "Webhook Receive Lead",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1184,
        -176
      ],
      "parameters": {
        "path": "incoming-lead",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "lastNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "2523c78d-8eb2-47a2-9a58-40658d77b5db",
      "name": "Normalize Lead Data",
      "type": "n8n-nodes-base.set",
      "position": [
        1616,
        -64
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "name",
              "type": "string",
              "value": "={{ $json.body?.name ?? $json.name ?? 'Lead' }}"
            },
            {
              "id": "2",
              "name": "email",
              "type": "string",
              "value": "={{ $json.body?.email ?? $json.email ?? '' }}"
            },
            {
              "id": "3",
              "name": "company",
              "type": "string",
              "value": "={{ $json.body?.company ?? $json.company ?? '' }}"
            },
            {
              "id": "4",
              "name": "website",
              "type": "string",
              "value": "={{ $json.body?.website ?? $json.website ?? '' }}"
            },
            {
              "id": "5",
              "name": "SCORE_THRESHOLD",
              "type": "number",
              "value": "={{ $json.SCORE_THRESHOLD ?? 7 }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "aae6950d-861a-41ed-a579-ac612d99b2cd",
      "name": "AI Score Lead",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1760,
        -64
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"gpt-4o-mini\",\n  \"messages\": [{\n    \"role\": \"user\",\n    \"content\": \"Score this B2B lead from 1-10. Reply with ONLY the number.\\n\\nName: {{ $json.name }}\\nEmail: {{ $json.email }}\\nCompany: {{ $json.company }}\\nWebsite: {{ $json.website }}\"\n  }],\n  \"temperature\": 0.3,\n  \"max_tokens\": 10\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "openAiApi"
      },
      "typeVersion": 4.2
    },
    {
      "id": "7326f10a-a44c-4cd9-98ca-378d3c740dac",
      "name": "Parse Score",
      "type": "n8n-nodes-base.code",
      "position": [
        1904,
        -32
      ],
      "parameters": {
        "jsCode": "const resp = $input.first().json;\nconst content = resp.choices?.[0]?.message?.content ?? resp.message?.content ?? '5';\nconst score = Math.min(10, Math.max(1, parseInt(String(content).match(/\\d+/)?.[0] || '5') || 5));\nlet lead = {};\ntry { lead = $('Normalize Lead Data').first().json; } catch (_) {}\nif (!lead || Object.keys(lead).length === 0) { try { lead = $('Sample Data').first().json; } catch (_) {} }\nconst threshold = lead.SCORE_THRESHOLD ?? 7;\nreturn { json: { ...lead, score, status: score >= threshold ? 'hot' : 'nurture', action: score >= threshold ? 'immediate_followup' : 'add_to_sequence', processed: true } };"
      },
      "typeVersion": 2
    },
    {
      "id": "a260869e-574a-4771-8fd5-dc9afc96d42d",
      "name": "Is Hot Lead?",
      "type": "n8n-nodes-base.if",
      "position": [
        2128,
        -32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "caseSensitive": true
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.score }}",
              "rightValue": "={{ $json.SCORE_THRESHOLD ?? 7 }}"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "868d32ba-fa5e-4756-b938-ffe7c935810a",
      "name": "Hot Lead",
      "type": "n8n-nodes-base.set",
      "position": [
        2336,
        -128
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "status",
              "type": "string",
              "value": "hot"
            },
            {
              "id": "2",
              "name": "action",
              "type": "string",
              "value": "immediate_followup"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a5dbb376-57f2-4b0f-8849-d31dda75b6fb",
      "name": "Nurture Lead",
      "type": "n8n-nodes-base.set",
      "position": [
        2336,
        80
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "status",
              "type": "string",
              "value": "nurture"
            },
            {
              "id": "2",
              "name": "action",
              "type": "string",
              "value": "add_to_sequence"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2b19f883-5abc-4ade-8bb3-62a0522bd05e",
      "name": "Merge Output",
      "type": "n8n-nodes-base.merge",
      "position": [
        2560,
        -32
      ],
      "parameters": {},
      "typeVersion": 3
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "0e1a53b6-814a-46c2-a728-a764c87b49df",
  "connections": {
    "Config": {
      "main": [
        [
          {
            "node": "Route by Source",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hot Lead": {
      "main": [
        [
          {
            "node": "Merge Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Test": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Score": {
      "main": [
        [
          {
            "node": "Is Hot Lead?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sample Data": {
      "main": [
        [
          {
            "node": "AI Score Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Hot Lead?": {
      "main": [
        [
          {
            "node": "Hot Lead",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Nurture Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Nurture Lead": {
      "main": [
        [
          {
            "node": "Merge Output",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "AI Score Lead": {
      "main": [
        [
          {
            "node": "Parse Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Source": {
      "main": [
        [
          {
            "node": "Normalize Lead Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Sample Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Lead Data": {
      "main": [
        [
          {
            "node": "AI Score Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook Receive Lead": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}