{
  "name": "Lead Capture from Contact Form",
  "nodes": [
    {
      "id": "wh-001",
      "name": "Invokati Dashboard Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [-600, 0],
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-capture-trigger",
        "options": {}
      }
    },
    {
      "id": "code-001",
      "name": "Extract & Validate Fields",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-400, 0],
      "parameters": {
        "jsCode": "const body = $input.first().json.body || $input.first().json;\nconst name = (body.name || '').trim();\nconst parts = name.split(' ');\nreturn [{\n  json: {\n    first_name: parts[0] || '',\n    last_name: parts.slice(1).join(' ') || '',\n    email: (body.email || '').toLowerCase().trim(),\n    phone: body.phone || '',\n    company_name: body.company || '',\n    job_title: body.job_title || '',\n    lead_source: body.source || 'Website',\n    notes: body.message || ''\n  }\n}];"
      }
    },
    {
      "id": "http-001",
      "name": "Capture Lead in Invokati",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-200, 0],
      "parameters": {
        "method": "POST",
        "url": "={{$env.INVOKATI_URL}}/api/leads",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [{ "name": "X-API-Key", "value": "={{$env.INVOKATI_API_KEY}}" }]
        },
        "options": { "allowUnauthorizedCerts": true },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            { "name": "first_name", "value": "={{$json.first_name}}" },
            { "name": "last_name", "value": "={{$json.last_name}}" },
            { "name": "email", "value": "={{$json.email}}" },
            { "name": "phone", "value": "={{$json.phone}}" },
            { "name": "company_name", "value": "={{$json.company_name}}" },
            { "name": "job_title", "value": "={{$json.job_title}}" },
            { "name": "lead_source", "value": "={{$json.lead_source}}" },
            { "name": "notes", "value": "={{$json.notes}}" },
            { "name": "lead_score", "value": "50" }
          ]
        }
      }
    },
    {
      "id": "email-001",
      "name": "Send Welcome Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [0, 0],
      "parameters": {
        "fromEmail": "={{$env.FROM_EMAIL}}",
        "toEmail": "={{$('Extract & Validate Fields').item.json.email}}",
        "subject": "Thanks for reaching out!",
        "text": "Hi {{$('Extract & Validate Fields').item.json.first_name}},\n\nThank you for contacting us. We'll be in touch shortly.\n\nBest regards"
      }
    },
    {
      "id": "respond-001",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [200, 0],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\"status\": \"success\", \"message\": \"Lead captured\"}"
      }
    }
  ],
  "connections": {
    "Invokati Dashboard Trigger": { "main": [[{ "node": "Extract & Validate Fields", "type": "main", "index": 0 }]] },
    "Extract & Validate Fields": { "main": [[{ "node": "Capture Lead in Invokati", "type": "main", "index": 0 }]] },
    "Capture Lead in Invokati": { "main": [[{ "node": "Send Welcome Email", "type": "main", "index": 0 }]] },
    "Send Welcome Email": { "main": [[{ "node": "Respond to Webhook", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "meta": { "instanceId": "invokati-example" }
}
