{
  "name": "Notify External System on Lead Status Change",
  "nodes": [
    {
      "id": "wh-001",
      "name": "Receive Status Change Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [-600, 0],
      "parameters": {
        "httpMethod": "POST",
        "path": "lead-status-change",
        "options": {}
      }
    },
    {
      "id": "switch-001",
      "name": "Route by New Status",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [-400, 0],
      "parameters": {
        "mode": "rules",
        "rules": {
          "values": [
            { "conditions": { "options": { "caseSensitive": false }, "conditions": [{ "leftValue": "={{$json.body.new_status}}", "rightValue": "Qualified", "operator": { "type": "string", "operation": "equals" } }] } },
            { "conditions": { "options": { "caseSensitive": false }, "conditions": [{ "leftValue": "={{$json.body.new_status}}", "rightValue": "Closed Won", "operator": { "type": "string", "operation": "equals" } }] } }
          ]
        }
      }
    },
    {
      "id": "http-crm",
      "name": "Push to External CRM",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [-200, -100],
      "parameters": {
        "method": "POST",
        "url": "={{$env.CRM_WEBHOOK_URL}}",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            { "name": "lead_id", "value": "={{$json.body.lead_id}}" },
            { "name": "status", "value": "={{$json.body.new_status}}" },
            { "name": "email", "value": "={{$json.body.email}}" },
            { "name": "changed_at", "value": "={{new Date().toISOString()}}" }
          ]
        }
      }
    },
    {
      "id": "http-slack",
      "name": "Notify Slack on Closed Won",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [-200, 100],
      "parameters": {
        "channel": "#sales-wins",
        "text": "🎉 Closed Won: ={{$json.body.first_name}} ={{$json.body.last_name}} (={{$json.body.company_name}})"
      }
    },
    {
      "id": "respond-001",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [0, 0],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\"status\": \"processed\"}"
      }
    }
  ],
  "connections": {
    "Receive Status Change Webhook": { "main": [[{ "node": "Route by New Status", "type": "main", "index": 0 }]] },
    "Route by New Status": {
      "main": [
        [{ "node": "Push to External CRM", "type": "main", "index": 0 }],
        [{ "node": "Notify Slack on Closed Won", "type": "main", "index": 0 }]
      ]
    },
    "Push to External CRM": { "main": [[{ "node": "Respond to Webhook", "type": "main", "index": 0 }]] },
    "Notify Slack on Closed Won": { "main": [[{ "node": "Respond to Webhook", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "meta": { "instanceId": "invokati-example" }
}
