{
  "name": "AutoLatam — FlujoDocs: documento → Google Sheets",
  "nodes": [
    {
      "parameters": {
        "pollTimes": { "item": [{ "mode": "everyMinute" }] },
        "simple": false,
        "filters": { "includeAttachments": true, "q": "has:attachment filename:pdf" },
        "options": {}
      },
      "id": "b2c3d4e5-0001-4000-8000-000000000001",
      "name": "Email con adjunto (Gmail)",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.2,
      "position": [-460, 300],
      "notes": "También puedes sustituirlo por un Webhook si tus documentos llegan por otra vía."
    },
    {
      "parameters": {
        "operation": "extractFromFile",
        "binaryPropertyName": "attachment_0"
      },
      "id": "b2c3d4e5-0002-4000-8000-000000000002",
      "name": "Extraer texto del PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [-240, 300]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "content": "=Extrae del documento los campos: proveedor, numero_documento, fecha, subtotal, impuestos, total. Responde SOLO con JSON válido. Documento: {{ $json.data ?? $json.text ?? '' }}"
            }
          ]
        },
        "jsonOutput": true,
        "options": { "temperature": 0 }
      },
      "id": "b2c3d4e5-0003-4000-8000-000000000003",
      "name": "IA: extraer campos clave",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [0, 300]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "TU_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Documentos",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "proveedor": "={{ $json.proveedor }}",
            "numero_documento": "={{ $json.numero_documento }}",
            "fecha": "={{ $json.fecha }}",
            "subtotal": "={{ $json.subtotal }}",
            "impuestos": "={{ $json.impuestos }}",
            "total": "={{ $json.total }}"
          },
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "b2c3d4e5-0004-4000-8000-000000000004",
      "name": "Volcar a Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [240, 300]
    }
  ],
  "connections": {
    "Email con adjunto (Gmail)": {
      "main": [[{ "node": "Extraer texto del PDF", "type": "main", "index": 0 }]]
    },
    "Extraer texto del PDF": {
      "main": [[{ "node": "IA: extraer campos clave", "type": "main", "index": 0 }]]
    },
    "IA: extraer campos clave": {
      "main": [[{ "node": "Volcar a Google Sheets", "type": "main", "index": 0 }]]
    }
  },
  "settings": { "executionOrder": "v1" },
  "active": false
}
