Quick overview
This workflow runs hourly to scan a Google Drive “Inbox” folder for PDF invoices, extract invoice fields with Google Gemini, and log the results to Google Sheets while filing PDFs into Processed or Review folders, with an optional summary email.
How it works
- Runs every hour on a schedule.
- Reads existing invoice rows from Google Sheets and lists all PDF files in the configured Google Drive Inbox folder.
- Downloads each PDF and extracts its text, routing files with little or no text to the Review path.
- Uses Google Gemini to extract structured invoice data (supplier, tax ID, invoice number, dates, amounts, currency, category, and description) from the PDF text.
- Checks for duplicates already present in Google Sheets and validates that subtotal + VAT − withholding matches the total within the configured tolerance to decide whether each file is OK, Review, or Duplicate.
- Renames and moves each PDF into the configured Processed (OK) or Review (Review/Duplicate) Google Drive folder.
- Appends a row to Google Sheets for all non-duplicate files and optionally sends a run summary email listing added invoices, review items, and duplicates.
Setup
- Create three Google Drive folders (Inbox, Processed, Review) and paste their folder IDs into Config, together with your company name and tax ID (so the AI can tell the supplier from you).
- Connect Google Drive credentials (OAuth2 or a service account with the three folders shared with it) in the Drive nodes.
- Create a Google Sheets spreadsheet (it can be empty: headers are created on the first run), select it in both Google Sheets nodes and connect Google Sheets credentials (OAuth2 or the same service account).
- Add a Google Gemini API credential (Google AI) for the Gemini model node.
- Optional: set notify_email and sender_email in Config and add an SMTP/Email Send credential to receive the summary email.
Requirements
- An n8n instance (cloud or self-hosted)
- A Google account with Google Drive and Google Sheets
- A Google Gemini API key
- Optional: an SMTP account for the summary email
Customization
- Edit the categories, language and amount tolerance in Config
- Adjust the extraction rules in the Extract invoice data prompt
- Swap Gemini for any other chat model supported by n8n, including a local one
- Change the schedule or the file naming pattern
Additional info
Invoices contain personal and financial data. For real invoices, use a paid Gemini plan (the free tier may use submitted data to improve Google products) or a local model. Scanned PDFs without a text layer are not sent to the AI: they are moved to Review for manual entry.