AutomationFlowsAI & RAG › AI Invoice Processing with Gmail & Google Drive

AI Invoice Processing with Gmail & Google Drive

Original n8n title: AI Invoice Processing

AI Invoice Processing. Uses gmailTrigger, googleDrive, chainLlm, lmChatOpenAi. Event-driven trigger; 25 nodes.

Event trigger★★★★☆ complexityAI-powered25 nodesGmail TriggerGoogle DriveChain LlmOpenAI ChatOutput Parser StructuredNotionAgent
AI & RAG Trigger: Event Nodes: 25 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow follows the Agent → Chainllm 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 →

Download .json
{
  "name": "AI Invoice Processing",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {
          "q": "filename:pdf has:attachment"
        },
        "options": {
          "downloadAttachments": true
        }
      },
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.2,
      "position": [
        -60,
        0
      ],
      "id": "e241c0cb-b46e-4c6c-b481-4ac1f05e00aa",
      "name": "Gmail Trigger",
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "7ef3261c-3cac-4f2f-a9f1-57d79183a85d",
              "name": "attachments",
              "value": "={{ $('Gmail Trigger').item.binary.keys() }}",
              "type": "array"
            },
            {
              "id": "6b9075da-0725-41e9-ba85-c9b5ed12ee3a",
              "name": "message_id",
              "value": "={{ $json.id }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        160,
        -160
      ],
      "id": "3fbca795-907d-4b62-8d73-48fb788377e8",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "fieldToSplitOut": "attachments",
        "include": "allOtherFields",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        320,
        -160
      ],
      "id": "dc5e9133-e211-462a-a251-752b19a7a4cc",
      "name": "Split Out"
    },
    {
      "parameters": {
        "mode": "combine",
        "advanced": true,
        "mergeByFields": {
          "values": [
            {
              "field1": "message_id",
              "field2": "id"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        540,
        -20
      ],
      "id": "24bbc9e8-51e4-491d-8388-d40bd7e78035",
      "name": "Merge"
    },
    {
      "parameters": {
        "inputDataFieldName": "={{ $json.attachments }}",
        "name": "={{ $('Gmail Trigger').item.json.headers.subject }}_{{ $json.attachments }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "value": "19bVVeXXC5b9DmwCH9eFiNKPityeoOiKY",
          "mode": "list",
          "cachedResultName": "Invoices From Gmail",
          "cachedResultUrl": "https://drive.google.com/drive/folders/19bVVeXXC5b9DmwCH9eFiNKPityeoOiKY"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        740,
        -20
      ],
      "id": "ec66258c-9325-4382-b410-44c3a2d06cb0",
      "name": "Upload file",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        940,
        -20
      ],
      "id": "116eaf4f-6b4b-4054-a7d6-fcc8bc99c5e0",
      "name": "Download file",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "pdf",
        "binaryPropertyName": "=data",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        1140,
        -20
      ],
      "id": "41f7babb-c969-4ecb-9467-1ee410285083",
      "name": "Extract from File",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Task Overview\nYou\u2019ll receive raw text extracted from PDF invoices. Your job is to identify the key details listed below and return them in a structured JSON object.\n\nInformation to Capture\n\ninvoice_name \u2013 the identifier or title of the invoice\n\ncompany_name \u2013 the name of the business that issued the invoice\n\ntotal_invoice_amount \u2013 the grand total shown on the invoice\n\nline_items \u2013 an array where each entry includes:\n\u2022 description \u2013 the item or service label\n\u2022 amount \u2013 the cost for that item\n\nOutput Format (example)\n{\n  \"invoice_name\": \"Invoice ABC-123\",\n  \"company_name\": \"Acme Corp\",\n  \"total_invoice_amount\": 1000,\n  \"line_items\": [\n    { \n      \"description\": \"Consulting services\", \"amount\": 100 \n    },\n    { \n      \"description\": \"Software license\", \"amount\": 800 \n    },\n    { \n      \"description\": \"Sales tax\", \"amount\": 100 \n    }\n  ]\n}\n\nGuidelines\n\nIf any detail is missing or unclear, make your best estimate or use null.\n\nProvide the most specific line-item labels available; use generic placeholders only when no description exists.\n\nVerify that the line-item amounts add up to the total invoice amount (minor rounding differences are acceptable).\n\nInput Placeholder\nText: {{ $json.text }}",
        "hasOutputParser": true,
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        2680,
        -40
      ],
      "id": "84d84f79-dda1-45ab-939a-6fe9ff885139",
      "name": "Basic LLM Chain"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        2640,
        140
      ],
      "id": "4ed4b15f-66a2-498e-af6e-4cc8842f8ad9",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n  \"invoice_name\": \"Invoice ABC-123\",\n  \"company_name\": \"Acme Corp\",\n  \"total_invoice_amount\": 1000,\n  \"line_items\": [\n    { \n      \"description\": \"Consulting services\", \"amount\": 100 \n    },\n    { \n      \"description\": \"Software license\", \"amount\": 800 \n    },\n    { \n      \"description\": \"Sales tax\", \"amount\": 100 \n    }\n  ]\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        2840,
        140
      ],
      "id": "78308a3e-9cb4-45cb-bc2c-6e48b1660380",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "226ccdb2-3d99-803f-9bca-da423b1441b3",
          "mode": "list",
          "cachedResultName": "Invoice Tracking Database",
          "cachedResultUrl": "https://www.notion.so/226ccdb23d99803f9bcada423b1441b3"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Subject|title",
              "title": "={{ $('Gmail Trigger').item.json.subject }}"
            },
            {
              "key": "Email|rich_text",
              "textContent": "={{ $('Gmail Trigger').item.json.from.value[0].address }}"
            },
            {
              "key": "Invoice URL|url",
              "urlValue": "={{ $('Upload file').item.json.webViewLink }}"
            },
            {
              "key": "Amount|number",
              "numberValue": "={{ $json.output.total_invoice_amount }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        3040,
        -40
      ],
      "id": "1fc53f6e-56ed-41fb-b0f8-3205b36f3d17",
      "name": "Create a database page",
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6b9b30bf-b866-437d-b244-f533b71aef51",
              "name": "line_items",
              "value": "={{ $('Basic LLM Chain').item.json.output.line_items }}",
              "type": "array"
            },
            {
              "id": "1ad359b2-bbd7-4a1f-997e-205054566b98",
              "name": "subject_id",
              "value": "={{ $json.id }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        3260,
        -40
      ],
      "id": "a7fb181a-87ce-45e9-b5f1-d7c55182faec",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "fieldToSplitOut": "=line_items",
        "include": "allOtherFields",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        3480,
        -40
      ],
      "id": "c45af3be-ca32-4e05-94fe-0968273b07b4",
      "name": "Split Out1"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        3960,
        -40
      ],
      "id": "9b0c2afe-ee4c-4742-a734-10bd2a0b643a",
      "name": "Loop Over Items"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        4220,
        -100
      ],
      "id": "e418fa51-bc78-47fe-a394-77373b87c5e0",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "226ccdb2-3d99-80ff-85c8-ef5279a5d40c",
          "mode": "list",
          "cachedResultName": "Invoice Line Items",
          "cachedResultUrl": "https://www.notion.so/226ccdb23d9980ff85c8ef5279a5d40c"
        },
        "simple": false,
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Invoice Subject|title",
              "title": "={{ $('Gmail Trigger').item.json.subject }}"
            },
            {
              "key": "Invoice Item|rich_text",
              "textContent": "={{ $json.line_items.description }}"
            },
            {
              "key": "Amount|number",
              "numberValue": "={{ $json.line_items.amount }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        4220,
        80
      ],
      "id": "0878a9d5-e65e-45c9-a58e-71122672fd62",
      "name": "Create a database page1",
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        1580,
        140
      ],
      "id": "3210a400-5e06-4f85-9cec-8ffc28385cf5",
      "name": "OpenAI Chat Model1",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n\"status\": \"\"\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        1800,
        140
      ],
      "id": "8edf9285-5518-44af-9367-64fdfe87080c",
      "name": "Structured Output Parser1"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "b5cbcaf4-583b-425c-b3e8-02789d87ec20",
              "leftValue": "={{ $json.output.status }}",
              "rightValue": "yes",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1920,
        -20
      ],
      "id": "9a19e37d-d7f8-4ea5-a038-42303385b3e5",
      "name": "If"
    },
    {
      "parameters": {
        "operation": "deleteFile",
        "fileId": {
          "__rl": true,
          "value": "={{ $('Download file').item.json.id }}",
          "mode": "id"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        2200,
        160
      ],
      "id": "c8692a26-e37e-4a93-a220-ac42f94cb0c0",
      "name": "Delete a file",
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "content": "# Get & Prepare Documents",
        "height": 700,
        "width": 1480,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -160,
        -340
      ],
      "id": "441aa298-90b4-4a1a-8c2b-2183bcaa06cb",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "# Check for The Invoice",
        "height": 700,
        "width": 1100,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1340,
        -340
      ],
      "id": "03ccbcae-ecb6-4628-91ad-f7efcd6d7425",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "# Extract & Save Information",
        "height": 700,
        "width": 1240,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2460,
        -340
      ],
      "id": "5c7f2136-f232-42e6-9afd-0d7d9a90b971",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "# Save Subitems",
        "height": 700,
        "width": 920
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        3720,
        -340
      ],
      "id": "6f5f47d1-6bfa-4218-a44b-788bb4cd86b3",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Based on the text decide if the text is about an invoice or not: {{ $json.text }}\n\nIf yes return \"yes\", if no return \"no\". Don't provide any additional information. Use only small letters",
        "hasOutputParser": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        1600,
        -20
      ],
      "id": "3e3f6ba0-637e-4fc3-bdb7-bd6897c70791",
      "name": "Invoice Controller"
    }
  ],
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          },
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Upload file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload file": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download file": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Invoice Controller",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Create a database page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a database page": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Split Out1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create a database page1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a database page1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Invoice Controller",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser1": {
      "ai_outputParser": [
        [
          {
            "node": "Invoice Controller",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete a file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Invoice Controller": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "036c9f3e-a2c6-42c5-baf5-605d2c711eff",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "iTJNttYhgKfAnddv",
  "tags": []
}

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.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

How this works

Streamline your invoice management by automating the extraction and organisation of financial data from incoming emails, saving hours of manual entry and reducing errors. This workflow suits small business owners or finance teams handling regular supplier invoices via Gmail, delivering structured data directly into Notion for easy tracking. The key step involves using an AI-powered LLM chain to intelligently parse invoice details like amounts, dates, and vendor information from downloaded PDF attachments stored in Google Drive.

Use this workflow when you receive a high volume of emailed invoices that need quick processing into a database, particularly if you're already using Gmail and Notion. Avoid it for non-digital invoices or when compliance requires human verification of every detail, as AI extraction isn't infallible. Common variations include swapping Notion for Google Sheets output or adding approval steps via email notifications before finalising entries.

About this workflow

AI Invoice Processing. Uses gmailTrigger, googleDrive, chainLlm, lmChatOpenAi. Event-driven trigger; 25 nodes.

Source: https://github.com/Khuzaima-AI-2112/n8n-automation-templates/blob/master/01_Bussiness-&-Support/08_Invoice-processing-system/AI+Invoice+Processing.json — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Awesome N8N Templates. Uses notion, lmChatOpenAi, outputParserStructured, chainLlm. Event-driven trigger; 36 nodes.

Notion, OpenAI Chat, Output Parser Structured +8
AI & RAG

Monthly Invoice Summarizer. Uses googleDriveTrigger, googleDrive, lmChatOpenAi, outputParserStructured. Event-driven trigger; 28 nodes.

Google Drive Trigger, Google Drive, OpenAI Chat +6
AI & RAG

The best content automation template in the market is now even better—with “deep research” on time-sensitive topics\! Unlike most n8n content automation templates that are mainly for “demo purposes,”

OpenAI, HTTP Request, XML +11
AI & RAG

This workflow is perfect for creators, solopreneurs, and personal brands who want to consistently publish bold, high-performing content on X (Twitter) — without writing a single line themselves. After

OpenAI Chat, Memory Buffer Window, Tool Workflow +10
AI & RAG

AI Blog Publisher – Automated Blog Content Workflow This workflow is designed for individuals and teams who regularly publish content on their blog and want to automate the entire process from start t

WordPress, HTTP Request, Memory Buffer Window +9