Quick overview
This workflow checks Gmail for emails with PDF invoice attachments, saves each PDF to a month-based Google Drive folder, uses OpenAI to extract key invoice fields, and appends qualifying invoices to a month-named tab in Google Sheets.
How it works
- Triggers hourly from Gmail (or can be run manually to backfill a date range) and downloads email attachments.
- Filters out emails from unwanted senders and extracts only PDF attachments from each message.
- Finds the current month’s folder in Google Drive, then uploads each PDF and builds shareable file and folder links.
- Extracts text from the PDF and sends it to an OpenAI-powered agent that returns structured invoice fields as strict JSON, retrying with an auto-fixing parser when needed.
- Checks whether Sales Tax or VAT is present and appends the invoice details (including PDF URL and Drive folder link) to a Google Sheets tab named for the current month.
- Waits briefly and continues processing the next PDF attachment.
Setup
- Connect Gmail, Google Drive, and Google Sheets credentials, and add an OpenAI API key for both OpenAI chat model connections.
- Update the Google Sheets document ID and ensure the target spreadsheet has columns that match the mapped fields (Company Name, Invoice Number, taxes, totals, links, and capture date).
- In Google Drive, set the parent folder ID in the Drive search step and create monthly subfolders named like YYYY-MM (for example, 2026-04).
- Edit the unwanted sender filter (or disable it) to match the email addresses you want to ignore.