{
  "name": "Lunexo – CRM Contact Sync",
  "nodes": [
    {
      "parameters": {
        "content": "## CRM Contact Sync\n\n**What it does:** Receives contact data via webhook, validates the email, syncs to your CRM via HTTP, and sends a welcome email.\n\n**Setup (~5 min):**\n1. Add your SMTP credentials\n2. Replace `YOUR_CRM_WEBHOOK_URL` with your CRM endpoint\n3. Replace `YOUR_ADMIN_EMAIL` with your inbox\n4. Activate the workflow\n5. Point your form/integration to the webhook URL\n\n**Variables to change:**\n- `YOUR_CRM_WEBHOOK_URL` — CRM API endpoint\n- `YOUR_ADMIN_EMAIL` — admin notification inbox",
        "height": 300,
        "width": 350,
        "color": 5
      },
      "id": "e7b30001-d4e5-6f7a-c8b9-700000000001",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [40, 80]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "crm-sync",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "e7b30001-d4e5-6f7a-c8b9-700000000002",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300],
      "webhookId": "e7b30001-d4e5-6f7a-c8b9-700000000020"
    },
    {
      "parameters": {
        "jsCode": "try {\n  const input = $input.first().json;\n  const body = input.body || input;\n  const name = body.name || body.fullName || '';\n  const email = (body.email || '').trim().toLowerCase();\n  const phone = body.phone || '';\n  const company = body.company || '';\n  const source = body.source || 'webhook';\n  const isValid = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email);\n\n  return [{ json: { name, email, phone, company, source, isValid } }];\n} catch (err) {\n  return [{ json: { name: '', email: '', phone: '', company: '', source: '', isValid: false, error: err.message } }];\n}"
      },
      "id": "e7b30001-d4e5-6f7a-c8b9-700000000003",
      "name": "Extract & Validate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "e7b30001-cond-0001",
              "leftValue": "={{ $json.isValid }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true"
              }
            }
          ],
          "combinator": "and"
        }
      },
      "id": "e7b30001-d4e5-6f7a-c8b9-700000000004",
      "name": "IF Email Valid",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [680, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "YOUR_CRM_WEBHOOK_URL",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            { "name": "name", "value": "={{ $json.name }}" },
            { "name": "email", "value": "={{ $json.email }}" },
            { "name": "phone", "value": "={{ $json.phone }}" },
            { "name": "company", "value": "={{ $json.company }}" },
            { "name": "source", "value": "={{ $json.source }}" }
          ]
        },
        "options": {}
      },
      "id": "e7b30001-d4e5-6f7a-c8b9-700000000005",
      "name": "POST to CRM",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 200]
    },
    {
      "parameters": {
        "fromEmail": "noreply@yourdomain.com",
        "toEmail": "={{ $json.email }}",
        "subject": "=Welcome, {{ $json.name }}!",
        "emailType": "html",
        "html": "=<div style=\"font-family:Arial,sans-serif;max-width:600px;margin:0 auto;padding:20px;\"><h2 style=\"color:#6C2BD9;\">Welcome, {{ $json.name }}!</h2><p>Thank you for getting in touch. We've received your information and will be in contact shortly.</p><p style=\"color:#888;font-size:12px;\">— Lunexo</p></div>",
        "options": {}
      },
      "id": "e7b30001-d4e5-6f7a-c8b9-700000000006",
      "name": "Send Welcome Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [1120, 200],
      "credentials": {
        "smtp": {
          "id": "CHANGE_ME",
          "name": "Your SMTP Account"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, message: 'Contact synced to CRM and welcome email sent.' }) }}",
        "options": {
          "responseCode": 200
        }
      },
      "id": "e7b30001-d4e5-6f7a-c8b9-700000000007",
      "name": "Respond OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [1340, 200]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ error: 'Invalid email address' }) }}",
        "options": {
          "responseCode": 400
        }
      },
      "id": "e7b30001-d4e5-6f7a-c8b9-700000000008",
      "name": "Respond 400",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [900, 440]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Extract & Validate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract & Validate": {
      "main": [
        [
          {
            "node": "IF Email Valid",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Email Valid": {
      "main": [
        [
          {
            "node": "POST to CRM",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond 400",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "POST to CRM": {
      "main": [
        [
          {
            "node": "Send Welcome Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Welcome Email": {
      "main": [
        [
          {
            "node": "Respond OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e7b30001-d4e5-6f7a-c8b9-700000000099",
  "meta": {
    "templateCredsSetupCompleted": false,
    "instanceId": "lunexo"
  },
  "pinData": {},
  "staticData": null,
  "tags": [
    { "name": "Lunexo" },
    { "name": "CRM" },
    { "name": "Contact" }
  ]
}