Skip to main content

Automatic email invoice archiving & data extraction with Gmail, Drive & AI

Workflow preview

Workflow preview
100%
Automatic email invoice archiving & data extraction with Gmail, Drive & AI preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Automated Invoice Archiving Automatically fetch, store, and extract key information from invoices received via email from your ISP or utility provider (electricity, gas, telecom, water, etc.).The w...

Best for

  • Invoice Processing automation workflows
  • AI Summarization automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.agent, n8n-nodes-base.code, n8n-nodes-base.googlesheets, n8n-nodes-base.httprequest, n8n-nodes-base.googledrive, n8n-nodes-base.gmail, n8n-nodes-base.scheduletrigger, n8n-nodes-base.stickynote

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Paolo Ronco.

Original n8n.io source

1.1 Workflow description

Title
Automatic email invoice archiving & data extraction with Gmail, Drive & AI
Workflow name
Automatic email invoice archiving & data extraction with Gmail, Drive & AI

Automated Invoice Archiving

Automatically fetch, store, and extract key information from invoices received via email from your ISP or utility provider (electricity, gas, telecom, water, etc.).The workflow saves the invoices to Google Drive (or optionally to your personal FTP/SFTP server) and logs all invoice details into Google Sheets via AI-powered extraction.

Read: Full setup Guide

How it works

  1. Scheduled TriggerRuns the workflow at a selected interval (e.g., every hour). You can freely adjust the timing.

  2. Gmail – Fetch MessagesReads your Gmail inbox and retrieves only messages coming from your ISP/utility provider’s email address, filtering for messages with PDF attachments.

  3. Gmail – Download Invoice Fetches the full email content and downloads the attached invoice (PDF).

  4. Google Drive – Upload File Uploads the invoice into a specific Google Drive folder of your choice.

  5. (Optional) Upload to FTP/SFTP Sends a copy of the invoice to your personal server via secure FTP/SFTP.

  6. AI Extraction Pipeline

  • Extract PDF Text – converts the PDF into text (OCR not required if text-based).

  • AI Agent (OpenRouter) – understands the invoice content and extracts structured fields (invoice number, date, provider name, total amount, tax info, line items, etc.)

  • Code Node – sanitizes and parses the JSON from the AI model.

  1. Google Sheets – Append Invoice DataAdds a new row to your Google Sheet with all parsed invoice fields.

  2. (Optional) CleanupAutomatically deletes:– the Gmail message– the temporary file in Google Drive(Useful when you only want your FTP or Sheets copy.)

Parameters to configure

Parameter Description Recommended configuration
Gmail Credentials OAuth2 credentials needed to read and delete emails. Create OAuth credentials on Google Cloud → enable Gmail API → paste Client ID & Secret into n8n → “Connect OAuth2”.
Sender Email Filter Email address your provider uses to send invoices. Example: [email protected], [email protected], [email protected]
Google Drive Folder Destination folder for saving invoices. Copy the folder ID from the Drive URL and paste it into folderId.
Google Drive Credentials OAuth2 connection for file uploads/deletions. Same Google Cloud project → enable Drive API → OAuth connect in n8n.
FTP/SFTP Server (optional) Upload invoices to your private server. Host / IP · Port · Username · Password or SSH Key · Destination path (e.g. /home/user/invoices/).
AI Model (OpenRouter) Large-language model used to parse invoice text. Example: gpt-4.1, llama-3.1, or any preferred OpenRouter model.
Google Sheets Document Destination spreadsheet for structured data. Create a Sheet → add columns (Vendor, Invoice Number, Date, Amount, Service Type, etc.) → insert documentId & sheet name.
Sheets Credentials (Service Account) Used for writing into Google Sheets. Create Service Account → download JSON → add to n8n → share the Sheet with the Service Account email.
Trigger Interval How often the workflow checks for new invoices. Every hour · every 30 minutes · daily at set ti

Node-by-node breakdown

1. Schedule Trigger

Runs at the interval you choose (default: hourly).Start → triggers entire workflow.


2. Gmail – Get Many Messages

Filters inbox items using:

  • Sender email (your ISP/utility address)

  • Has attachment

  • Unread or recent messages

Downloads metadata + attachment references.


3. Filter – Contains Attachment

Ensures only messages with binary attachments continue.


4. Gmail – Get Invoice

Downloads:

  • Full email JSON

  • The invoice PDF (binary data)


5. Google Drive – Upload File

Uploads invoice PDF with a dynamic filename:

{{ $json.from.value[0].name }}-{{ $json.date }}.pdf

Requires:

  • Google Drive OAuth2 credentials

  • Folder ID (destination directory)


6. HTTP Request – Download File

Retrieves the raw PDF file from Google Drive for further processing.


7. (Optional) FTP/SFTP Upload

Uploads the PDF to your server using:

  • Host / IP

  • Port (default 22)

  • Username

  • Password or private key

  • Destination path

Filename is sanitized to ensure Unix compatibility.


8. (Optional) Delete Temporary File

Deletes the Google Drive file if you don’t want duplicates.


9. (Optional) Delete Gmail Message

Removes the original email once processed (optional inbox cleanup).


10. Extract from File (PDF → Text)

Reads the PDF and extracts raw text for AI processing.


11. OpenRouter Chat Model

LLM backend for the AI agent. Provides:

  • invoice parsing

  • field extraction

  • structured reasoning


12. AI Agent – Extract Invoice Fields

The agent is instructed to return strict JSON only, containing keys such as:

  • vendor_name

  • invoice_number

  • invoice_date

  • total_amount

  • tax_details

  • line_items[]

  • po_number

  • po_date

Works for most standard PDF invoices.


13. Code – Clean & Parse JSON

Sanitizes the AI output:

  • Removes markdown fences

  • Extracts valid JSON

  • Parses into a clean JS object

If the AI output is malformed, debugging info is returned.


14. Google Sheets – Append Data

Appends the extracted fields into a structured row.Example mappings:

  • Vendor{{ $json.vendor_name }}

  • Invoice Number{{ $json.invoice_number }}

  • Date{{ $json.invoice_date }}

  • Amount{{ $json.total_amount }}

  • Service Type{{ $json.line_items[0].description }}


💡 Tips & best practices

  • Add multiple sender filters if you have more than one utility provider.

  • Ensure invoices are text-based PDFs for best extraction results.

  • Use Google Drive as a reliable long-term archive, or keep only FTP if you prefer local storage.

  • Create charts in Google Sheets for tracking:

    • Monthly utility cost trends

    • Year-over-year comparison

    • Consumption spikes (if included in invoices)


⚠️ Important notes

  • Utility invoices contain personal and financial data. Keep your FTP/SFTP server secure.

  • Google APIs require proper OAuth2 or Service Account setup; misconfiguration may cause permission errors.

  • This workflow is for personal automation, not a replacement for official fiscal archiving.

  • AI extraction quality depends on invoice formatting and the model you choose.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - AI_Agent-fields

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2.2

Block 2 - Code_extractFields

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 3 - GoogleSheets_save

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.7

Block 4 - downloadFile

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 5 - GoogleDrive-upload-file

Type / Role
n8n-nodes-base.googleDrive - googleDrive
Config choices
Version 3

Block 6 - Gmail-Get_Invoice

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 7 - Delete a message

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 8 - Schedule Trigger

Type / Role
n8n-nodes-base.scheduleTrigger - scheduleTrigger
Config choices
Version 1.2

Block 9 - Get many messages

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 10 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - Extract from File1

Type / Role
n8n-nodes-base.extractFromFile - extractFromFile
Config choices
Version 1

Block 12 - OpenRouter Chat Model1

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenRouter - lmChatOpenRouter
Config choices
Version 1

Block 13 - Delete a file1

Type / Role
n8n-nodes-base.googleDrive - googleDrive
Config choices
Version 3

Block 14 - Filter-contains_attachment

Type / Role
n8n-nodes-base.filter - filter
Config choices
Version 2.2

Block 15 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 16 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 17 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 18 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 19 - Sticky Note6

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 20 - Sticky Note7

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 21 - Code in JavaScript

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 22 - If

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.3

Block 23 - Check: Message already processed

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.7

Block 24 - Sticky Note8

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Showing the first 24 of 26 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Automatic email invoice archiving & data extraction with Gmail, Drive & AI
Complexity advanced
Nodes 26
Categories Invoice Processing, AI Summarization
Author Paolo Ronco
Published 17 Nov 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/10923/10923.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Automatic email invoice archiving & data extraction with Gmail, Drive & AI do?

Automated Invoice Archiving Automatically fetch, store, and extract key information from invoices received via email from your ISP or utility provider (electricity, gas, telecom, water, etc.).The w...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Invoice Processing, AI Summarization use case.