{
    "name": "Beeznez starter: web form lead to CRM and alert",
    "nodes": [
        {
            "parameters": {
                "content": "## Web form lead to CRM\n**Untested starter** from Beeznez Tech. Not run in production.\n\n1. Point your form tool at this workflow production webhook URL (POST, JSON with name, email and message).\n2. Replace the CRM URL and key, or swap that node for your CRM own n8n node.\n3. Add SMTP credentials and your addresses to both email nodes.\n4. The duplicate check only remembers emails while the workflow is active.\n5. Store only the fields you need and say on the form what it is for.\n\nKeep a person in the loop before anything reaches a customer.",
                "height": 320,
                "width": 380
            },
            "id": "1bb93049-c7c6-4688-b9f6-16e0c020390d",
            "name": "READ ME",
            "type": "n8n-nodes-base.stickyNote",
            "typeVersion": 1,
            "position": [
                -420,
                -40
            ]
        },
        {
            "parameters": {
                "httpMethod": "POST",
                "path": "beeznez-lead",
                "responseMode": "responseNode",
                "options": []
            },
            "id": "5dee56a9-84c6-4f2e-a756-9412f32efe11",
            "name": "Form webhook",
            "type": "n8n-nodes-base.webhook",
            "typeVersion": 2,
            "position": [
                -20,
                200
            ]
        },
        {
            "parameters": {
                "jsCode": "const b = $input.item.json.body || {};\nconst email = String(b.email || '').trim().toLowerCase();\nconst valid = /^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(email);\nconst store = $getWorkflowStaticData('global');\nstore.seen = store.seen || {};\nconst duplicate = valid && !!store.seen[email];\nif (valid && !duplicate) { store.seen[email] = new Date().toISOString(); }\nreturn { json: {\n  valid,\n  duplicate,\n  name: String(b.name || '').trim(),\n  email,\n  message: String(b.message || '').trim().slice(0, 2000),\n  received: new Date().toISOString()\n} };",
                "mode": "runOnceForEachItem"
            },
            "id": "ccb18a4a-ae3d-4a6e-b252-62ac450e524e",
            "name": "Validate and de-duplicate",
            "type": "n8n-nodes-base.code",
            "typeVersion": 2,
            "position": [
                200,
                200
            ]
        },
        {
            "parameters": {
                "conditions": {
                    "options": {
                        "caseSensitive": true,
                        "leftValue": "",
                        "typeValidation": "strict",
                        "version": 2
                    },
                    "conditions": [
                        {
                            "id": "0828e0de-9422-4995-bf04-4b91cc38fdbc",
                            "leftValue": "={{ $json.valid }}",
                            "rightValue": "",
                            "operator": {
                                "type": "boolean",
                                "operation": "true",
                                "singleValue": true
                            }
                        },
                        {
                            "id": "fa0fed55-3c10-4df1-a449-770a16e76994",
                            "leftValue": "={{ $json.duplicate }}",
                            "rightValue": "",
                            "operator": {
                                "type": "boolean",
                                "operation": "false",
                                "singleValue": true
                            }
                        }
                    ],
                    "combinator": "and"
                },
                "options": []
            },
            "id": "ddbf4f82-752d-471e-91df-559ffdc55591",
            "name": "Valid and new?",
            "type": "n8n-nodes-base.if",
            "typeVersion": 2,
            "position": [
                420,
                200
            ]
        },
        {
            "parameters": {
                "method": "POST",
                "url": "https://YOUR-CRM.example.com/api/contacts",
                "sendHeaders": true,
                "headerParameters": {
                    "parameters": [
                        {
                            "name": "Authorization",
                            "value": "Bearer YOUR_CRM_KEY"
                        }
                    ]
                },
                "sendBody": true,
                "specifyBody": "json",
                "jsonBody": "={{ JSON.stringify({ name: $json.name, email: $json.email, notes: $json.message, source: \"web form\" }) }}",
                "options": []
            },
            "id": "014416fe-7c5d-4ca1-b692-bfae3873971f",
            "name": "Create or update contact (CRM)",
            "type": "n8n-nodes-base.httpRequest",
            "typeVersion": 4.2,
            "position": [
                880,
                200
            ],
            "onError": "continueErrorOutput"
        },
        {
            "parameters": {
                "fromEmail": "you@example.com",
                "toEmail": "team@example.com",
                "subject": "=New lead: {{ $(\"Validate and de-duplicate\").item.json.name }}",
                "emailFormat": "text",
                "text": "=Name: {{ $(\"Validate and de-duplicate\").item.json.name }}\nEmail: {{ $(\"Validate and de-duplicate\").item.json.email }}\nReceived: {{ $(\"Validate and de-duplicate\").item.json.received }}\n\nMessage:\n{{ $(\"Validate and de-duplicate\").item.json.message }}",
                "options": []
            },
            "id": "33f4844a-4cd1-4300-88ac-3e13b5c7b354",
            "name": "Alert: new lead",
            "type": "n8n-nodes-base.emailSend",
            "typeVersion": 2.1,
            "position": [
                1100,
                100
            ]
        },
        {
            "parameters": {
                "respondWith": "json",
                "responseBody": "{ \"ok\": true }",
                "options": {
                    "responseCode": 200
                }
            },
            "id": "2ba05efc-1a7c-421c-b3b9-e9e646fda4f0",
            "name": "Respond: OK",
            "type": "n8n-nodes-base.respondToWebhook",
            "typeVersion": 1.1,
            "position": [
                1320,
                100
            ]
        },
        {
            "parameters": {
                "fromEmail": "you@example.com",
                "toEmail": "team@example.com",
                "subject": "=LEAD NOT SAVED: {{ $(\"Validate and de-duplicate\").item.json.email }}",
                "emailFormat": "text",
                "text": "=The CRM step failed. Please add this lead by hand.\n\nName: {{ $(\"Validate and de-duplicate\").item.json.name }}\nEmail: {{ $(\"Validate and de-duplicate\").item.json.email }}\nMessage:\n{{ $(\"Validate and de-duplicate\").item.json.message }}",
                "options": []
            },
            "id": "829312ef-080f-4026-bc48-14b7750ce706",
            "name": "Alert: CRM step failed",
            "type": "n8n-nodes-base.emailSend",
            "typeVersion": 2.1,
            "position": [
                1100,
                320
            ]
        },
        {
            "parameters": {
                "respondWith": "json",
                "responseBody": "{ \"ok\": false, \"error\": \"Could not save the lead\" }",
                "options": {
                    "responseCode": 500
                }
            },
            "id": "4681b871-4e5b-4cfb-9721-3e7f2c25a57b",
            "name": "Respond: error",
            "type": "n8n-nodes-base.respondToWebhook",
            "typeVersion": 1.1,
            "position": [
                1320,
                320
            ]
        },
        {
            "parameters": {
                "respondWith": "json",
                "responseBody": "{ \"ok\": false, \"error\": \"Invalid or duplicate email\" }",
                "options": {
                    "responseCode": 422
                }
            },
            "id": "4770c751-fe78-4f4a-a977-6c3e9014cc85",
            "name": "Respond: invalid or duplicate",
            "type": "n8n-nodes-base.respondToWebhook",
            "typeVersion": 1.1,
            "position": [
                640,
                420
            ]
        }
    ],
    "connections": {
        "Form webhook": {
            "main": [
                [
                    {
                        "node": "Validate and de-duplicate",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Validate and de-duplicate": {
            "main": [
                [
                    {
                        "node": "Valid and new?",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Valid and new?": {
            "main": [
                [
                    {
                        "node": "Create or update contact (CRM)",
                        "type": "main",
                        "index": 0
                    }
                ],
                [
                    {
                        "node": "Respond: invalid or duplicate",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Create or update contact (CRM)": {
            "main": [
                [
                    {
                        "node": "Alert: new lead",
                        "type": "main",
                        "index": 0
                    }
                ],
                [
                    {
                        "node": "Alert: CRM step failed",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Alert: new lead": {
            "main": [
                [
                    {
                        "node": "Respond: OK",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Alert: CRM step failed": {
            "main": [
                [
                    {
                        "node": "Respond: error",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        }
    },
    "active": false,
    "settings": {
        "executionOrder": "v1"
    },
    "tags": []
}