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

⚑ 531 views · 🧾 Invoice Processing

πŸ’‘ Pro Tip β€” HTTP Request scraping tends to break when sites update their markup. If you’re scraping a major platform, check if ScraperNode covers it β€” it has maintained scrapers for LinkedIn, Instagram, TikTok, YouTube, and 20+ other platforms that return structured data.

View All Scrapers

Description

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.

Asset1.png

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

  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

ParameterDescriptionRecommended configuration
Gmail CredentialsOAuth2 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 FilterEmail address your provider uses to send invoices.Example: billing@your-isp.com, invoices@utility.it, ciao@octopusenergy.it
Google Drive FolderDestination folder for saving invoices.Copy the folder ID from the Drive URL and paste it into folderId.
Google Drive CredentialsOAuth2 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 DocumentDestination 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 IntervalHow 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:

Downloads metadata + attachment references.


3. Filter – Contains Attachment

Ensures only messages with binary attachments continue.


4. Gmail – Get Invoice

Downloads:


5. Google Drive – Upload File

Uploads invoice PDF with a dynamic filename:

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

Requires:


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:

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:


12. AI Agent – Extract Invoice Fields

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

Works for most standard PDF invoices.


13. Code – Clean & Parse JSON

Sanitizes the AI output:

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:


πŸ’‘ Tips & best practices


⚠️ Important notes

πŸ”— Nodes Used

Google Sheets, HTTP Request, Google Drive, FTP, Gmail, Schedule Trigger

πŸ“₯ Import

Download workflow.json and import into n8n: Workflow menu β†’ Import from File

πŸ“– Importing guide Β· πŸ”‘ Credential setup