This workflow corresponds to n8n.io template #4376 — we link there as the canonical source.
This workflow follows the Agent → Gmail Trigger recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"meta": {
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "70ca3a90-55c8-4e46-9278-6a8fd3d107cd",
"name": "Gmail Trigger",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-1820,
220
],
"parameters": {
"simple": false,
"filters": {
"labelIds": [
"Label_1393502052621954450"
]
},
"options": {
"downloadAttachments": true
},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "f7dcff0f-7e98-4042-a33e-2fc32d876908",
"name": "Create blank spreadsheet",
"type": "n8n-nodes-base.googleSheets",
"position": [
-780,
220
],
"parameters": {
"title": "=invoice_{{ $now }}",
"options": {},
"resource": "spreadsheet",
"sheetsUi": {
"sheetValues": [
{
"title": "=invoice_details"
}
]
}
},
"executeOnce": false,
"typeVersion": 4.5
},
{
"id": "9769ad04-a41c-4d55-806a-042b7d00e131",
"name": "Move spreadsheet in invoice folder",
"type": "n8n-nodes-base.googleDrive",
"position": [
-560,
220
],
"parameters": {
"fileId": {
"__rl": true,
"mode": "id",
"value": "={{ $json.spreadsheetId }}"
},
"driveId": {
"__rl": true,
"mode": "list",
"value": "My Drive",
"cachedResultUrl": "https://drive.google.com/drive/my-drive",
"cachedResultName": "My Drive"
},
"folderId": {
"__rl": true,
"mode": "list",
"value": "1JIdajTJvK6gj4bRjniBJvHEJbQ1pn3AM",
"cachedResultUrl": "https://drive.google.com/drive/folders/1JIdajTJvK6gj4bRjniBJvHEJbQ1pn3AM",
"cachedResultName": "invoices"
},
"operation": "move"
},
"typeVersion": 3
},
{
"id": "f9dbfe55-70b0-4abc-9745-9f4a65d5d1c2",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-1180,
480
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini"
},
"options": {
"responseFormat": "json_object"
}
},
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "00c59142-6079-4e9c-9374-ad487e48f072",
"name": "Attachment Verification",
"type": "n8n-nodes-base.filter",
"position": [
-1600,
220
],
"parameters": {
"options": {
"ignoreCase": false
},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "efd974d9-aa20-461a-86ae-6e0a16d1527d",
"operator": {
"type": "object",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $('Gmail Trigger').item.binary }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "8a29ac14-be2b-468a-97fa-540d28e80006",
"name": "Extract Invoice data",
"type": "n8n-nodes-base.extractFromFile",
"position": [
-1380,
220
],
"parameters": {
"options": {},
"operation": "pdf",
"binaryPropertyName": "={{ $('Attachment Verification').item.binary.keys() }}"
},
"typeVersion": 1
},
{
"id": "ae08cdc8-fcf9-4891-be86-b2dcf6f35278",
"name": "Preparing Final data",
"type": "n8n-nodes-base.code",
"position": [
-340,
220
],
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of $input$json.output.first().json.outputeach one\n\nlet invoice_details = $('Invoice AI Agent').item.json.output\n\nreturn JSON.parse(invoice_details)"
},
"typeVersion": 2
},
{
"id": "7615a5b0-8761-43e2-82b0-32ac5c772f44",
"name": "Final Spreadsheet with Invoice data",
"type": "n8n-nodes-base.googleSheets",
"position": [
-140,
220
],
"parameters": {
"columns": {
"value": {},
"schema": [
{
"id": "billed_to",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "billed_to",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "invoice_number",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "invoice_number",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "date_of_issue",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "date_of_issue",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "due_date",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "due_date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "item_0_description",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "item_0_description",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "item_0_quantity",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "item_0_quantity",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "item_0_rate",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "item_0_rate",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "item_0_amount",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "item_0_amount",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "tax_0_cgst_rate",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "tax_0_cgst_rate",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "tax_0_cgst_amount",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "tax_0_cgst_amount",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "tax_0_sgst_rate",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "tax_0_sgst_rate",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "tax_0_sgst_amount",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "tax_0_sgst_amount",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "item_0_total_amount",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "item_0_total_amount",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "subtotal",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "subtotal",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "total",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "total",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "terms",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "terms",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "conditions_instructions",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "conditions_instructions",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "company_name",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "company_name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "company_mobile",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "company_mobile",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "company_email",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "company_email",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "company_website",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "company_website",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "payment_transaction_ids",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "payment_transaction_ids",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "mode_of_payment",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "mode_of_payment",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "billing_address",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "billing_address",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "shipping_address",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "shipping_address",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "place_of_supply",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "place_of_supply",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "place_of_delivery",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "place_of_delivery",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "gst_registration_no",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "gst_registration_no",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "pan_no",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "pan_no",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "autoMapInputData",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "name",
"value": "invoice_details"
},
"documentId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Create blank spreadsheet').item.json.spreadsheetId }}"
}
},
"typeVersion": 4.5
},
{
"id": "e68aa386-7150-4070-a5d7-1dcb963b620d",
"name": "Invoice AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-1160,
220
],
"parameters": {
"text": "={{ $json.text }}",
"options": {
"systemMessage": "you are an financial advisor , who reads the array of data to identify certain elements of an Invoice, from the input data and provide a json response. use only following specified keys \nfor example:\n{\n\"billed_to\": \"John\",\n\"invoice_number\": \"569871234\",\n\"date_of_issue\": \"2025-05-21\",\n\"due_date\": \"2025-05-25\",\n\"item_0_description\": \"Computer CPU\",\n\"item_0_quantity\": 6,\n\"item_0_rate\": 15,\n\"item_0_amount\": 90,\n\"item_1_description\": \"Chair Wooden\",\n\"item_1_quantity\": 8,\n\"item_1_rate\": 10,\n\"item_1_amount\": 80,\n\"subtotal\": 170.00,\n\"discount\": 20.00,\n\"total\": 150.00,\n\"terms\": \"Sold items not be acceptable\",\n\"conditions_instructions\": \"xyaABC\",\n\"company_name\": \"Digital Electronics\",\n\"company_mobile\": \"987654321\",\n\"company_email\": \"user@example.com\",\n\"company_website\": \"www.abc.com\"\n}"
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 1.9,
"alwaysOutputData": false
},
{
"id": "335a80c5-ad86-4379-b1a6-9a2ef7285f3c",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2860,
100
],
"parameters": {
"width": 880,
"height": 1520,
"content": "AI Invoice Processor Agent: Email to Structured Data\nAutomatically extract, analyze, and organize invoice data from Gmail attachments into structured Google Sheets. Perfect for:\n\u2705 Accountants & bookkeepers \u2014 eliminate manual data entry from invoices\n\u2705 Small businesses \u2014 streamline invoice processing and tracking\n\u2705 Finance teams \u2014 automate accounts payable workflows\n\n\u2699\ufe0f What's Used\nn8n Nodes:\nGmail Trigger \u2192 File Extraction \u2192 AI Agent \u2192 OpenAI Chat Model \u2192 Google Sheets \u2192 Google Drive\nExternal Tools:\n\nGmail API \u2013 Monitor specific labeled emails with attachments\nPDF Extraction \u2013 Convert invoice PDFs to readable text\nOpenAI GPT-4 \u2013 Intelligent invoice data extraction and structuring\nGoogle Sheets \u2013 Create organized spreadsheets with invoice details\nGoogle Drive \u2013 Automatically organize files in invoice folders\n\n\n\ud83d\udd11 Setup \u2013 Credentials Needed\n\nGmail OAuth2 \u2192 Access emails and download attachments\nOpenAI API Key \u2192 For AI-powered invoice data extraction\nGoogle Sheets OAuth2 \u2192 Create and populate spreadsheets\nGoogle Drive OAuth2 \u2192 Organize files in designated folders\n\n\n\ud83d\udce7 Gmail Setup Required\nCreate a Gmail label (e.g., \"Invoice Processing\") and apply it to emails containing invoice attachments. The workflow will monitor this label for new emails every minute.\n\n\ud83d\ude80 Workflow Steps\n\nEmail Monitoring\nContinuously watches Gmail for new emails with specific labels and attachments\nAttachment Verification\nFilters emails to ensure they contain PDF attachments before processing\nData Extraction\nConverts PDF invoices to text and extracts readable content\nAI-Powered Analysis\nGPT processes invoice text and extracts structured data including:\n\nCompany details and contact information\nInvoice numbers, dates, and due dates\nLine items with quantities, rates, and amounts\nTax calculations (CGST, SGST, VAT)\nPayment terms and billing addresses\n\n\nSpreadsheet Creation\nCreates timestamped Google Sheets with organized invoice data\nFile Organization\nMoves processed spreadsheets to designated Drive folders for easy access\n\n\n\ud83d\udcca Extracted Data Fields\nThe AI identifies and organizes 25+ invoice elements:\n\nHeader Info: Billed to, invoice number, dates\nLine Items: Description, quantity, rate, amount\nTax Details: CGST/SGST rates and amounts\nCompany Info: Name, contact details, GST numbers\nPayment Info: Transaction IDs, payment methods\nAddresses: Billing, shipping, delivery locations\n\n\n\ud83d\udca1 Pro Tips\n\nUse clear Gmail labels for different invoice types (vendors, clients, etc.)\nEnsure invoice PDFs are text-based (not scanned images) for best results\nCreate separate Drive folders for different accounting periods\nReview AI extraction accuracy and refine prompts as needed\nSet up email filters to automatically apply labels to vendor emails\n\n\n\ud83d\udee0\ufe0f Customize It\n\nAdd invoice approval workflows with email notifications\nConnect to accounting software (QuickBooks, Xero, SAP)\nInclude OCR processing for scanned invoice images\nAdd duplicate invoice detection and alerts\nCreate automated payment reminders based on due dates"
},
"typeVersion": 1
}
],
"connections": {
"Gmail Trigger": {
"main": [
[
{
"node": "Attachment Verification",
"type": "main",
"index": 0
}
]
]
},
"Invoice AI Agent": {
"main": [
[
{
"node": "Create blank spreadsheet",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Invoice AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Extract Invoice data": {
"main": [
[
{
"node": "Invoice AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Preparing Final data": {
"main": [
[
{
"node": "Final Spreadsheet with Invoice data",
"type": "main",
"index": 0
}
]
]
},
"Attachment Verification": {
"main": [
[
{
"node": "Extract Invoice data",
"type": "main",
"index": 0
}
]
]
},
"Create blank spreadsheet": {
"main": [
[
{
"node": "Move spreadsheet in invoice folder",
"type": "main",
"index": 0
}
]
]
},
"Move spreadsheet in invoice folder": {
"main": [
[
{
"node": "Preparing Final data",
"type": "main",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
openAiApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Transform your invoice processing from manual data entry into an intelligent automation system. This powerful n8n workflow monitors Gmail for invoice attachments, extracts data using AI-powered analysis, and creates organized Google Sheets with all relevant financial information…
Source: https://n8n.io/workflows/4376/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
> Note: This workflow uses sticky notes extensively to document each logical section of the automation. Sticky notes are mandatory and already included to explain OCR, AI parsing, folder logic, dup
Enterprise-grade resume screening automation built for production environments. This workflow combines intelligent AI analysis with comprehensive error handling to ensure reliable processing of candid
This template is for founders, finance teams, and solo operators who receive lots of invoices by email and want them captured automatically in a single, searchable source of truth. If you’re tired of
This template is for HR teams, recruiters, and companies that receive job applications via email and want to automatically screen and evaluate candidates using AI. Ideal for organisations processing a
Colombian Invoices Processing. Uses splitInBatches, lmChatOpenAi, toolCalculator, outputParserStructured. Event-driven trigger; 23 nodes.