Escaneo de correos electrónicos y creación de órdenes de compra en Google Sheets

Intermedio

Este es unDocument Extraction, AI Summarizationflujo de automatización del dominio deautomatización que contiene 15 nodos.Utiliza principalmente nodos como If, Set, Code, Cron, Gmail. Extraer órdenes de compra de Gmail y guardar en Google Sheets usando Gemini AI

Requisitos previos
  • Cuenta de Google y credenciales de API de Gmail
  • Credenciales de API de Google Sheets
  • Clave de API de Google Gemini
Vista previa del flujo de trabajo
Visualización de las conexiones entre nodos, con soporte para zoom y panorámica
Exportar flujo de trabajo
Copie la siguiente configuración JSON en n8n para importar y usar este flujo de trabajo
{
  "id": "xfKuFCSndnxYSb8t",
  "meta": {
    "instanceId": "bbc3fa3cd7d64d8ff0c4877d98dee68ce7dadacc5e089546680c915b3e5a212b",
    "templateCredsSetupCompleted": true
  },
  "name": "Email scanning and purchase order creation in Google Sheet",
  "tags": [],
  "nodes": [
    {
      "id": "7fa9ff57-fb2c-4db0-a3ff-4f2fa1d2184f",
      "name": "Obtener múltiples mensajes",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -2608,
        -592
      ],
      "webhookId": "38e977e5-65c8-4b40-b201-bbe71fea8aea",
      "parameters": {
        "limit": 100,
        "simple": false,
        "filters": {
          "readStatus": "unread",
          "receivedAfter": "={{ $today.minus({ days: 1 }).toISODate() }}"
        },
        "options": {
          "downloadAttachments": true
        },
        "operation": "getAll"
      },
      "typeVersion": 2.1
    },
    {
      "id": "e87d2e42-8bd6-473b-87ed-aeb6ec643e58",
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "position": [
        -2784,
        -592
      ],
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "aad75605-ee41-4fc8-8e61-5e5932a30d67",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        -2112,
        -592
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "60e07c88-8125-4a64-8212-14935fc3d73a",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $('Filter emails').item.binary}}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "f1d9876b-8e9d-4824-9650-a3641f294532",
      "name": "Agente de IA",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1648,
        -576
      ],
      "parameters": {
        "text": "=# Role  \nYou are an Expert AI Agent specialized in reading emails, extracting purchase order details, enriching them with product information using the Google Sheet tool, and normalizing dates into calendar weeks (Kalenderwoche).  \n\n# Task  \n- Input: {{ $('If').item.json.text }}  \n- Context: The email may contain purchase order details either in:  \n  - A formatted table, or  \n  - A freeform paragraph.  \n- Language: The email text can be in any language. You must understand and process it.  \n\n# Instructions  \n1. Read the email text carefully.  \n2. Identify purchase order details, including:  \n   - Product/package name  \n   - Quantity / number of items  \n   - Any other order-related details (sizes, variants, etc. if available).  \n3. Detect **dates or time expressions** that refer to delivery, booking, or campaign execution.  \n   - If the text contains a direct week reference (e.g., *KW36*), use it directly.  \n   - If the text contains a month or vague time reference (e.g., *end of October*), convert it into the appropriate calendar week(s).  \n     - *“Start of X month”* → first calendar week of that month.  \n     - *“Mid of X month”* → middle calendar week of that month.  \n     - *“End of X month”* → last calendar week of that month.  \n   - Use ISO week numbering (Monday as first day of the week).  \n4. Populate both `Kalenderwoche Start` and `Kalenderwoche Ende`.  \n   - If only one week is identified, set both Start and End to the same week.  \n   - If a date range is mentioned, map Start and End accordingly.  \n5. Query the **Google Sheet tool** to fetch full product details (e.g., product code, price, description, stock availability).  \n6. Merge the extracted order information with the Google Sheet product details.  \n7. **Return only the final `items` array as JSON. Do not include order_id, customer, or notes.**  \n8. Ensure all keys are translated into the email’s language or standardized consistently.  \n\n# Output Format  \nReturn **only this JSON array**:  \n```json\n[\n  { \"Laufende Nummer\":\"<string>\",\n    \"Lieferant\":\"<string>\",\n    \"Lieferanten-Nr\": \"<number or null>\",\n    \"Marke\": \"<string or null>\",\n    \"Marken-Nr\": \"<number or null>\",\n    \"Kalenderwoche Start\": \"<string, e.g., KW36>\",\n    \"Kalenderwoche Ende\": \"<string, e.g., KW36>\",\n    \"Marketing Status\": \"<string or null>\",\n    \"Paket\": \"<string>\",\n    \"Produkt\": \"<string>\",\n    \"Länder-Aktivierung\": \"<string or null>\",\n    \"Kosten\": \"<number or null>\",\n    \"quantity\": \"<number>\"\n  }\n]\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "id": "68af1754-d9c2-4ab3-b3e6-a72deaea11df",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -1664,
        -384
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "b3adb22f-622c-48c1-83eb-2d3f4551251e",
      "name": "Obtener fila(s) en hoja en Google Sheets",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        -1488,
        -368
      ],
      "parameters": {
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "="
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "a6ef8668-1b13-4f96-820d-1dd5d25b693f",
      "name": "Agregar fila en hoja",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -1088,
        -576
      ],
      "parameters": {
        "columns": {
          "value": {
            "Marke": "={{ $json.Marke }}",
            "Paket": "={{ $json.Paket }}",
            "Kosten": "={{ $json.Kosten }}",
            "Produkt": "={{ $json.Produkt }}",
            "Lieferant": "={{ $json.Lieferant }}",
            "Marken-Nr": "={{ $json[\"Marken-Nr\"] }}",
            "Lieferanten-Nr": "={{ $json[\"Lieferanten-Nr\"] }}",
            "Laufende Nummer": "={{ $json[\"Laufende Nummer\"] }}",
            "Marketing Status": "={{ $json[\"Marketing Status\"] }}",
            "Kalenderwoch Start": "={{ $json[\"Kalenderwoche Start\"] }}",
            "Kalenderwoche Ende": "={{ $json[\"Kalenderwoche Ende\"] }}",
            "Länder-Aktivierung": "={{ $json[\"Länder-Aktivierung\"] }}"
          },
          "schema": [
            {
              "id": "Laufende Nummer",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Laufende Nummer",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Lieferant",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Lieferant",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Lieferanten-Nr",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Lieferanten-Nr",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Marke",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Marke",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Marken-Nr",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Marken-Nr",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Kalenderwoch Start",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Kalenderwoch Start",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Kalenderwoche Ende",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Kalenderwoche Ende",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Marketing Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Marketing Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Paket",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Paket",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Produkt",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Produkt",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Länder-Aktivierung",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Länder-Aktivierung",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Kosten",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Kosten",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "id",
          "value": "="
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "="
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Hqjs4o2PKY8T8cY1",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "90d90230-7fea-431e-af80-e22753b41856",
      "name": "Nota adhesiva",
      "type": "n8n-nodes-base.stickyNote",
      "disabled": true,
      "position": [
        -2800,
        -704
      ],
      "parameters": {
        "width": 528,
        "height": 320,
        "content": "## Scan Email on every minute and read new emails.\n**Get new emails frequently and filer them which has purchase order**"
      },
      "typeVersion": 1
    },
    {
      "id": "de0dcfdd-bb42-4170-8506-d2fa8a5846cd",
      "name": "Nota adhesiva1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2144,
        -736
      ],
      "parameters": {
        "width": 400,
        "height": 368,
        "content": "## Check the document has attachment\n**Check for email without attachment. To read purchase order from the email body**"
      },
      "typeVersion": 1
    },
    {
      "id": "24b56bad-9b5a-4710-9cc8-8fdcb07bd864",
      "name": "Establecer claves de salida final",
      "type": "n8n-nodes-base.set",
      "position": [
        -1888,
        -576
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a05c046c-6afb-421d-8b9e-128d0960d006",
              "name": "final_json_keys",
              "type": "array",
              "value": "=[\n  \"Laufende Nummer\",\n  \"Lieferant\",\n  \"Lieferanten-Nr\",\n  \"Marke\",\n  \"Marken-Nr\",\n  \"Kalenderwoche\\nStart\",\n  \"Kalenderwoche\\nEnde\",\n  \"Marketing Status\",\n  \"Paket\",\n  \"Produkt\",\n  \"Länder-Aktivierung\",\n  \"Kosten\"\n]\n"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "24616df2-e7e4-4105-830f-8bc095f818f7",
      "name": "Filtrar correos electrónicos",
      "type": "n8n-nodes-base.filter",
      "position": [
        -2416,
        -592
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "6b9ca560-7c08-40e0-9d9b-8a916ff1368c",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.subject }}",
              "rightValue": "=Marketing"
            },
            {
              "id": "518e65fe-c130-4a27-821b-20f6c51b2dd7",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.subject }}",
              "rightValue": "Buchungsanfrage"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "0c0cb36a-2ff1-4b53-8830-90d000ddbe51",
      "name": "Reformateado para subir a hoja Google",
      "type": "n8n-nodes-base.code",
      "position": [
        -1264,
        -576
      ],
      "parameters": {
        "jsCode": "// Input from previous node\nconst input = items[0].json.output;\n\n// Remove markdown ```json ... ``` wrappers if present\nconst cleaned = input.replace(/```json|```/g, '').trim();\n\nlet parsed;\ntry {\n  parsed = JSON.parse(cleaned);\n} catch (error) {\n  throw new Error(`Failed to parse JSON: ${error.message}\\nRaw input: ${cleaned}`);\n}\n\n// Return each object as separate item in n8n\nreturn parsed.map(obj => ({ json: obj }));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "6867e395-dcc0-491d-b406-c914418d30b0",
      "name": "Nota adhesiva2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1712,
        -672
      ],
      "parameters": {
        "width": 352,
        "height": 464,
        "content": "## AI Agent to read and summarize the order."
      },
      "typeVersion": 1
    },
    {
      "id": "4c38683c-1398-432e-b780-ad7d51a0d238",
      "name": "Nota adhesiva3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1312,
        -688
      ],
      "parameters": {
        "width": 352,
        "height": 304,
        "content": "## Append purchase order to Google sheet\n"
      },
      "typeVersion": 1
    },
    {
      "id": "06417501-207f-45f9-8239-3676f14f9457",
      "name": "Nota adhesiva4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3152,
        -1280
      ],
      "parameters": {
        "width": 480,
        "height": 544,
        "content": "## 📧 Email Reading & Purchase Order Creation (AI-powered)\n\n**✨ What it does**  \n- ⏱ Reads unread emails every minute  \n- 🎯 Filters emails based on **Subject**  \n- 🤖 Uses Gemini AI to summarize emails & extract purchase order details  \n- 📊 Appends purchase order data to Google Sheets  \n\n**🛠 Requirements**  \n- 📩 Gmail account access to fetch unread emails  \n- 🔑 Gemini AI credentials for summarization & extraction  \n- 📑 Google Sheet with predefined purchase order headers  \n\n**⚙️ Setup Instructions**  \n1. 🔗 Set up Google Sheets & Gmail credentials in n8n  \n2. 📝 Configure the filter node with your subject rules  \n3. 🤝 Connect Gemini AI with the correct credentials  \n4. 📂 Create & configure a Google Sheet with the necessary purchase order headers  \n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6ef223ac-0d4b-424d-b174-f3072229fbe6",
  "connections": {
    "aad75605-ee41-4fc8-8e61-5e5932a30d67": {
      "main": [
        [],
        [
          {
            "node": "24b56bad-9b5a-4710-9cc8-8fdcb07bd864",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e87d2e42-8bd6-473b-87ed-aeb6ec643e58": {
      "main": [
        [
          {
            "node": "7fa9ff57-fb2c-4db0-a3ff-4f2fa1d2184f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "f1d9876b-8e9d-4824-9650-a3641f294532": {
      "main": [
        [
          {
            "node": "0c0cb36a-2ff1-4b53-8830-90d000ddbe51",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "24616df2-e7e4-4105-830f-8bc095f818f7": {
      "main": [
        [
          {
            "node": "aad75605-ee41-4fc8-8e61-5e5932a30d67",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "7fa9ff57-fb2c-4db0-a3ff-4f2fa1d2184f": {
      "main": [
        [
          {
            "node": "24616df2-e7e4-4105-830f-8bc095f818f7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "24b56bad-9b5a-4710-9cc8-8fdcb07bd864": {
      "main": [
        [
          {
            "node": "f1d9876b-8e9d-4824-9650-a3641f294532",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "68af1754-d9c2-4ab3-b3e6-a72deaea11df": {
      "ai_languageModel": [
        [
          {
            "node": "f1d9876b-8e9d-4824-9650-a3641f294532",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "b3adb22f-622c-48c1-83eb-2d3f4551251e": {
      "ai_tool": [
        [
          {
            "node": "f1d9876b-8e9d-4824-9650-a3641f294532",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "0c0cb36a-2ff1-4b53-8830-90d000ddbe51": {
      "main": [
        [
          {
            "node": "a6ef8668-1b13-4f96-820d-1dd5d25b693f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Preguntas frecuentes

¿Cómo usar este flujo de trabajo?

Copie el código de configuración JSON de arriba, cree un nuevo flujo de trabajo en su instancia de n8n y seleccione "Importar desde JSON", pegue la configuración y luego modifique la configuración de credenciales según sea necesario.

¿En qué escenarios es adecuado este flujo de trabajo?

Intermedio - Extracción de documentos, Resumen de IA

¿Es de pago?

Este flujo de trabajo es completamente gratuito, puede importarlo y usarlo directamente. Sin embargo, tenga en cuenta que los servicios de terceros utilizados en el flujo de trabajo (como la API de OpenAI) pueden requerir un pago por su cuenta.

Flujos de trabajo relacionados recomendados

Automatización de solicitudes de reserva de hoteles de Gmail a Google Sheets con GPT-4o-mini
Registrar automáticamente solicitudes de reserva de hoteles de Gmail en Google Sheets con GPT-4o-mini
If
Set
Code
+
If
Set
Code
29 NodosGtaras
Extracción de documentos
Enviar resumen de correo electrónico y calendario diario a Slack usando Gemini AI y Google Workspace
Resumen diario de correos electrónicos y calendarios enviado a Slack usando Gemini AI y Google Workspace
Code
Cron
Gmail
+
Code
Cron
Gmail
20 NodosSayone Technologies
Varios
Flujo de trabajo de análisis de sentimiento de reseñas de Google
Analizar reseñas de Google My Business y enviar informes de sentimiento a Slack con Gemini
Set
Code
Slack
+
Set
Code
Slack
25 NodosSayone Technologies
Resumen de IA
Pruebas de FAQ sobre límites de velocidad y autenticación de API
Usar GPT-4o-mini, Google Sheets y recordatorios de Slack para automatizar las pruebas de calidad de preguntas frecuentes de la API
If
Set
Code
+
If
Set
Code
19 NodosRahul Joshi
Extracción de documentos
Automatización de la investigación de debida diligencia de proveedores usando Gemini y Jina AI
Automatizar la investigación de debida diligencia de proveedores con Gemini y Jina AI
If
Set
Code
+
If
Set
Code
27 NodosAdnan
Extracción de documentos
Automatización de extracción de metadatos y variables de artículos académicos, de Gemini a Google Sheets
Automatización de extracción de metadatos y variables de artículos académicos, de Gemini a Google Sheets
Set
Code
Wait
+
Set
Code
Wait
39 NodosOwenLee
Extracción de documentos
Información del flujo de trabajo
Nivel de dificultad
Intermedio
Número de nodos15
Categoría2
Tipos de nodos11
Descripción de la dificultad

Adecuado para usuarios con experiencia intermedia, flujos de trabajo de complejidad media con 6-15 nodos

Autor
Sayone Technologies

Sayone Technologies

@sayonetech

SayOne Technologies is a digital transformation and IT services company headquartered in India, with a strong focus on web, mobile, and AI-driven solutions for the retail tech space. With over a decade of experience, SayOne partners with global businesses to build scalable applications, optimize inventory and operations using next-gen AI, and deliver customer-centric digital products.

Enlaces externos
Ver en n8n.io

Compartir este flujo de trabajo

Categorías

Categorías: 34