{
  "name": "New Lead \u2192 CRM + Welcome Email",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "new-lead",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "Webhook: New Lead",
      "type": "n8n-nodes-base.webhook",
      "position": [
        240,
        300
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.body.email }}",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "id": "validate-email",
      "name": "Has Email?",
      "type": "n8n-nodes-base.if",
      "position": [
        460,
        300
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "notionApi",
        "resource": "databasePage",
        "operation": "create",
        "databaseId": "={{ $env.NOTION_LEADS_DB_ID }}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "titleValue": "={{ $json.body.name }}"
            },
            {
              "key": "Email|email",
              "emailValue": "={{ $json.body.email }}"
            },
            {
              "key": "Source|select",
              "selectValue": "={{ $json.body.source ?? 'Website' }}"
            },
            {
              "key": "Status|select",
              "selectValue": "New"
            },
            {
              "key": "Created|date",
              "dateValue": "={{ $now.toISO() }}"
            }
          ]
        }
      },
      "id": "add-to-notion",
      "name": "Add to Notion CRM",
      "type": "n8n-nodes-base.notion",
      "position": [
        680,
        220
      ],
      "typeVersion": 2.2
    },
    {
      "parameters": {
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "gmailOAuth2",
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $('Webhook: New Lead').item.json.body.email }}",
        "subject": "Welcome! Here's what happens next",
        "emailType": "html",
        "message": "<h2>Hi {{ $('Webhook: New Lead').item.json.body.name }},</h2><p>Thanks for your interest! I'll be in touch within 24 hours.</p><p>In the meantime, check out <a href='https://misciael.gumroad.com'>my automation tools</a>.</p><p>Best,<br>Miscia</p>"
      },
      "id": "send-welcome-email",
      "name": "Send Welcome Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        680,
        360
      ],
      "typeVersion": 2.1
    }
  ],
  "connections": {
    "Webhook: New Lead": {
      "main": [
        [
          {
            "node": "Has Email?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Email?": {
      "main": [
        [
          {
            "node": "Add to Notion CRM",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Welcome Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "_meta": {
    "description": "Captures a new lead via webhook, adds them to a Notion CRM database, and sends an automatic welcome email via Gmail.",
    "requiredCredentials": [
      "Notion API",
      "Gmail OAuth2"
    ],
    "variables": [
      "NOTION_LEADS_DB_ID"
    ],
    "category": "Lead Gen / CRM",
    "n8nVersion": ">=1.0.0"
  }
}