{
  "name": "Bella - Lead Magnet Delivery",
  "nodes": [
    {
      "id": "51620fda-37b4-4b03-809b-a9056a923098",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "bella-lead-magnet",
        "responseMode": "responseNode"
      }
    },
    {
      "id": "357447d6-17ba-4d2a-a431-d50ddc1665e8",
      "name": "Code: Parse & Validate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        0
      ],
      "parameters": {
        "jsCode": "const body = $input.first().json.body || $input.first().json;\nconst required = ['email', 'lead_magnet_type'];\nfor (const f of required) {\n  if (!body[f]) throw new Error(`Missing required field: ${f}`);\n}\nreturn [{ json: {\n  email: body.email,\n  name: body.name || 'there',\n  school_name: body.school_name || '',\n  lead_magnet_type: body.lead_magnet_type,\n  received_at: new Date().toISOString(),\n} }];"
      }
    },
    {
      "id": "ff29ea02-6c10-4b61-a5bb-f85f60e72a6d",
      "name": "Switch: Lead Magnet Type",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        560,
        0
      ],
      "parameters": {
        "mode": "rules",
        "rules": {
          "values": [
            {
              "outputKey": "checklist",
              "conditions": {
                "options": {
                  "caseSensitive": false,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.lead_magnet_type }}",
                    "rightValue": "checklist",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true
            },
            {
              "outputKey": "audit",
              "conditions": {
                "options": {
                  "caseSensitive": false,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.lead_magnet_type }}",
                    "rightValue": "audit",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true
            },
            {
              "outputKey": "templates-pack",
              "conditions": {
                "options": {
                  "caseSensitive": false,
                  "leftValue": "",
                  "typeValidation": "strict"
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.lead_magnet_type }}",
                    "rightValue": "templates-pack",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "f6b79694-0f11-40b5-88b2-658292241fb3",
      "name": "Code: Checklist Email Body",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        840,
        -200
      ],
      "parameters": {
        "jsCode": "const { name, email, school_name } = $input.first().json;\nreturn [{ json: {\n  to: email,\n  subject: 'Your SIS Compliance Checklist is Ready!',\n  html: `<h2>Hi ${name},</h2><p>Thank you for your interest! Here is your SIS Compliance Checklist for ${school_name || 'your school'}.</p><p>Download: <a href='https://bella.learnleadai.com/assets/sis-checklist.pdf'>SIS Checklist PDF</a></p><br><p>- The Bella Team</p>`,\n  magnet_type: 'checklist',\n} }];"
      }
    },
    {
      "id": "20622051-129f-4789-afad-460f741b6516",
      "name": "Note: Email Credentials",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1120,
        -350
      ],
      "parameters": {
        "content": "\u26a0\ufe0f Add your email sending credentials to the HTTP Request nodes below and enable them.",
        "height": 80,
        "width": 320,
        "color": 4
      }
    },
    {
      "id": "6a9bbc86-f47e-4088-a14e-fda38f25ff60",
      "name": "HTTP Request: Send Checklist Email",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1120,
        -200
      ],
      "disabled": true,
      "parameters": {
        "method": "POST",
        "url": "https://YOUR_EMAIL_API/send",
        "sendBody": true,
        "contentType": "json",
        "body": {
          "to": "={{ $json.to }}",
          "subject": "={{ $json.subject }}",
          "html": "={{ $json.html }}"
        }
      }
    },
    {
      "id": "a0aa6732-d2a4-4dc5-b7db-c5384210cecc",
      "name": "Note: Cal.com Link",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        840,
        80
      ],
      "parameters": {
        "content": "Update Cal.com link below to your actual Bella SIS audit booking URL.",
        "height": 80,
        "width": 320,
        "color": 4
      }
    },
    {
      "id": "e0c1cfe4-cbfb-4c1e-9217-22876746309d",
      "name": "Set: Audit Redirect",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [
        1120,
        0
      ],
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "83dea9b4-585b-4ff9-ba47-b5f31cd5939f",
              "name": "redirect_url",
              "value": "https://cal.com/bella/sis-audit",
              "type": "string"
            },
            {
              "id": "3d236684-8968-473a-8e6f-afaaba78693f",
              "name": "magnet_type",
              "value": "audit",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "81b73336-faf0-49e6-8dfb-7abedf03b524",
      "name": "Code: Template Pack Email Body",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        840,
        280
      ],
      "parameters": {
        "jsCode": "const { name, email, school_name } = $input.first().json;\nreturn [{ json: {\n  to: email,\n  subject: 'Your SIS Templates Pack is Ready!',\n  html: `<h2>Hi ${name},</h2><p>Here are your SIS Templates for ${school_name || 'your school'}.</p><p>Download: <a href='https://bella.learnleadai.com/assets/sis-templates.zip'>Templates Pack</a></p><br><p>- The Bella Team</p>`,\n  magnet_type: 'templates-pack',\n} }];"
      }
    },
    {
      "id": "3685862a-9b1c-4768-87ef-614ef3ba80bd",
      "name": "HTTP Request: Send Templates Email",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1120,
        280
      ],
      "disabled": true,
      "parameters": {
        "method": "POST",
        "url": "https://YOUR_EMAIL_API/send",
        "sendBody": true,
        "contentType": "json",
        "body": {
          "to": "={{ $json.to }}",
          "subject": "={{ $json.subject }}",
          "html": "={{ $json.html }}"
        }
      }
    },
    {
      "id": "be9f5fc3-5a6f-4923-87af-9149a280313c",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        1400,
        0
      ],
      "parameters": {
        "mode": "passThrough",
        "output": "all"
      }
    },
    {
      "id": "37efc5e5-eb2c-4678-81e8-5dc817ac3d65",
      "name": "Code: Log Lead",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1680,
        0
      ],
      "parameters": {
        "jsCode": "const item = $input.first().json;\nreturn [{ json: {\n  email: item.email || item.to || '',\n  magnet_type: item.magnet_type || 'unknown',\n  logged_at: new Date().toISOString(),\n} }];"
      }
    },
    {
      "id": "16da9c7a-ab84-4314-a4cb-4804bdbc9e04",
      "name": "Note: Google Sheets",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1960,
        -120
      ],
      "parameters": {
        "content": "\u26a0\ufe0f Connect Google Sheets here \u2014 add your Sheet ID and enable this node.",
        "height": 80,
        "width": 320,
        "color": 4
      }
    },
    {
      "id": "8126d04a-1dec-4e0d-a3ff-341c4d505d9d",
      "name": "HTTP Request: Log to Sheet",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1960,
        0
      ],
      "disabled": true,
      "parameters": {
        "method": "POST",
        "url": "https://sheets.googleapis.com/v4/spreadsheets/YOUR_SHEET_ID/values/Sheet1!A1:append",
        "sendBody": true,
        "contentType": "json",
        "body": {}
      }
    },
    {
      "id": "14ee3cf5-5ee2-41f3-ae37-c7316808ad2b",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        2240,
        0
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"success\": true, \"message\": \"Check your email!\" }"
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Code: Parse & Validate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Parse & Validate": {
      "main": [
        [
          {
            "node": "Switch: Lead Magnet Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch: Lead Magnet Type": {
      "main": [
        [
          {
            "node": "Code: Checklist Email Body",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set: Audit Redirect",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code: Template Pack Email Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Checklist Email Body": {
      "main": [
        [
          {
            "node": "HTTP Request: Send Checklist Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request: Send Checklist Email": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set: Audit Redirect": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Code: Template Pack Email Body": {
      "main": [
        [
          {
            "node": "HTTP Request: Send Templates Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request: Send Templates Email": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Code: Log Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Log Lead": {
      "main": [
        [
          {
            "node": "HTTP Request: Log to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request: Log to Sheet": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}