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

⚑ 989 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

Quick overview

Automatically collect invoice PDFs from Gmail, archive them in Google Drive or an optional FTP/SFTP server, extract structured invoice data with AI, and record the results in Google Sheets.

How it works

  1. Scheduled inbox check β€” A Schedule Trigger periodically checks Gmail for invoice messages matching the configured sender and attachment filters.
  2. Invoice download β€” Gmail nodes retrieve the matching message and download its PDF attachment.
  3. Document archiving β€” The PDF is uploaded to Google Drive and can optionally be copied to an FTP/SFTP server.
  4. Text extraction β€” n8n extracts text from text-based PDFs for AI processing without requiring OCR.
  5. AI extraction β€” An OpenRouter-backed AI Agent extracts structured fields such as vendor, invoice number, date, amount, tax information, line items, and purchase-order data.
  6. Output normalization β€” A Code node cleans and parses the model response into usable JSON.
  7. Google Sheets logging β€” Extracted invoice fields are appended to the configured spreadsheet.
  8. Optional cleanup β€” The processed Gmail message and temporary Google Drive file can be removed when no longer required.

Setup

  1. Import the workflow β€” Import workflow.json into n8n.
  2. Connect Gmail β€” Configure Gmail OAuth2 and update sender/message filters for the providers you want to process.
  3. Connect Google Drive β€” Configure Drive OAuth2 and select the destination folder for invoice PDFs.
  4. Configure OpenRouter β€” Add OpenRouter credentials and select the model used by the extraction agent.
  5. Connect Google Sheets β€” Select the spreadsheet, configure credentials, and map extracted fields to its columns.
  6. Review optional storage and cleanup β€” Configure FTP/SFTP if required and enable deletion steps only when intentionally removing source or temporary files.
  7. Test and activate β€” Process a sample invoice, verify the PDF and extracted fields, then activate the workflow.

Requirements

Customization

Additional info

Invoice documents may contain personal and financial information. Protect credentials, storage locations, spreadsheets, and FTP/SFTP access appropriately. AI extraction accuracy depends on document structure and the selected model. Validate extracted data before using it for accounting or fiscal processes. This workflow is an automation aid, not a replacement for legally compliant fiscal or document-retention systems.

πŸ”— 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