{
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "export-notion",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "b1517fcf-358a-4f5c-b345-cb9987cc2e33",
      "name": "\ud83d\udce5 Webhook export-notion",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        400,
        -128
      ],
      "notes": "URL: https://TU-N8N.com/webhook/export-notion\nEste es el endpoint que llama el dashboard al click en bot\u00f3n Notion.\nDos modos:\n- action='init_schema' \u2192 crea/actualiza columnas de la database\n- action='export_row'  \u2192 crea una fila con los datos del cliente"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "action-check",
              "leftValue": "={{ $json.body.action }}",
              "rightValue": "init_schema",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "a022d08e-b43b-41d2-9b16-37ea68de8eff",
      "name": "\ud83d\udd00 \u00bfInit Schema o Export Row?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        640,
        -128
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.notion.com/v1/pages",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_NOTION_TOKEN"
            },
            {
              "name": "Notion-Version",
              "value": "2022-06-28"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{\n  JSON.stringify({\n    \"parent\": { \"database_id\": \"YOUR_NOTION_DATABASE_ID\" },\n    \"properties\": {\n      \"Cliente\": { \"title\": [{ \"text\": { \"content\": $json.body.user_id || \"Sin ID\" } }] },\n      \"Urgencia\": { \"select\": { \"name\": $json.body.urgency_level || \"Medium\" } },\n      \"Pa\u00eds\": { \"select\": { \"name\": $json.body.country || \"Desconocido\" } },\n      \"Plan\": { \"select\": { \"name\": $json.body.plan || \"N/A\" } },\n      \"MRR\": { \"number\": $json.body.mrr_usd || 0 },\n      \"Score\": { \"number\": $json.body.churn_risk_score || 0 },\n      \"Estado\": { \"select\": { \"name\": \"Pendiente\" } },\n      \"Fecha\": { \"date\": { \"start\": new Date().toISOString().split('T')[0] } }\n    },\n    \"children\": [\n      {\n        \"object\": \"block\",\n        \"type\": \"heading_2\",\n        \"heading_2\": {\n          \"rich_text\": [{ \"type\": \"text\", \"text\": { \"content\": \"\ud83e\udd16 Hip\u00f3tesis de Churn\" } }],\n          \"color\": \"blue_background\"\n        }\n      },\n      {\n        \"object\": \"block\",\n        \"type\": \"paragraph\",\n        \"paragraph\": {\n          \"rich_text\": [{ \"type\": \"text\", \"text\": { \"content\": ($json.body.churn_reason_hypothesis || \"Sin datos\").substring(0, 2000) } }]\n        }\n      },\n      {\n        \"object\": \"block\",\n        \"type\": \"heading_2\",\n        \"heading_2\": {\n          \"rich_text\": [{ \"type\": \"text\", \"text\": { \"content\": \"\u26a1 Acci\u00f3n Recomendada\" } }],\n          \"color\": \"orange_background\"\n        }\n      },\n      {\n        \"object\": \"block\",\n        \"type\": \"paragraph\",\n        \"paragraph\": {\n          \"rich_text\": [{ \"type\": \"text\", \"text\": { \"content\": ($json.body.recommended_action || \"Sin acci\u00f3n\").substring(0, 2000) } }]\n        }\n      }\n    ]\n  })\n}}",
        "options": {}
      },
      "id": "b25b1179-b192-4918-85f2-2d9c7615ebfa",
      "name": "\ud83d\udcdd POST \u00b7 Crear Fila en Notion",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        -128
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"success\": true, \"message\": \"Operaci\u00f3n completada en Notion\" }",
        "options": {
          "responseCode": 200,
          "responseHeaders": {
            "entries": [
              {
                "name": "Content-Type",
                "value": "application/json"
              },
              {
                "name": "Access-Control-Allow-Origin",
                "value": "*"
              }
            ]
          }
        }
      },
      "id": "4b842cc7-6af0-4905-9558-1615216883b3",
      "name": "\u2705 Responder \u00c9xito",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1120,
        -128
      ]
    }
  ],
  "connections": {
    "\ud83d\udce5 Webhook export-notion": {
      "main": [
        [
          {
            "node": "\ud83d\udd00 \u00bfInit Schema o Export Row?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd00 \u00bfInit Schema o Export Row?": {
      "main": [
        [],
        [
          {
            "node": "\ud83d\udcdd POST \u00b7 Crear Fila en Notion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udcdd POST \u00b7 Crear Fila en Notion": {
      "main": [
        [
          {
            "node": "\u2705 Responder \u00c9xito",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}