n8n

How to Automate Gmail Invoices to Google Drive and Sheets?

Save time on invoice admin by pulling bills from email, reading the data, and storing clean records. This setup watches a Gmail inbox, unpacks invoice files, and builds a searchable log in Google Sheets while saving PDFs to Google Drive. It suits personal finance and small finance teams that receive electronic invoices by email, including formats used in Colombia.

Every 30 minutes, a Gmail trigger looks for new messages with zip attachments. The flow unzips the files, keeps only PDF and XML, and extracts text from both. An AI model reads the content and returns structured fields like invoice number, date, NIT, totals, and CUFE, using a schema to keep the format steady. A calculator confirms that subtotal plus tax equals total, then the PDF is uploaded to Google Drive, renamed with date and invoice number, and the invoice row is added or updated in Google Sheets with a unique key to avoid duplicates.

You need Gmail, Google Drive, Google Sheets, and OpenAI access to run it. Point the Drive node to a folder and set the target sheet. Expect faster month end close, fewer copy paste mistakes, and a clean archive you can search by date or number.

What are the key features?

  • Gmail polling every 30 minutes with a search that only grabs emails with zip attachments
  • Automatic unzip of attachments and filtering to PDF and XML files
  • PDF text extraction with all pages joined for better reading
  • XML parsing and conversion to JSON for clean structured data
  • Merges PDF and XML content and sends it to an AI model with a defined schema
  • Calculator check confirms subtotal plus tax equals total before saving
  • Uploads the original PDF to Google Drive and renames it by date and invoice number
  • Appends or updates Google Sheets with a unique key to block duplicates
  • Batch loop handles multiple files inside one zip without manual steps

What are the benefits?

  • Reduce manual work from 2 hours to 10 minutes per batch
  • Automate up to 90 percent of invoice data entry
  • Improve data accuracy by verifying totals with a math check
  • Connect Gmail, Google Drive, Google Sheets, and OpenAI in one flow
  • Handle many invoices at once by processing zip files and batches
  • Prevent duplicate records using a unique key for each invoice

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Gmail, Google Drive, Google Sheets and OpenAI. See the Tools Required section above for links to create accounts with these services.
  3. Open the Gmail Trigger node. In the credential dropdown, click Create new credential and connect your Gmail account using OAuth2. Allow read access and attachments.
  4. In the Gmail Trigger node, set the Search query to has:attachment filename:zip and set the polling to every 30 minutes or the interval you prefer.
  5. Open the OpenAI Chat Model node. Click Create new credential and paste your API key from your OpenAI account. Pick your model and save.
  6. Open the Google Drive nodes. Click Create new credential to connect your Google Drive with OAuth2. Choose the Drive and select or paste the folder where PDFs will be stored.
  7. Open the Google Sheets node. Click Create new credential to connect your Google account. Choose the target spreadsheet and the sheet name where invoice rows will be saved.
  8. Verify the column mapping in the Google Sheets node. Ensure fields like Key, CUFE, NIT, Fecha Emision, Subtotal, IVA, Total, and Numero Factura exist in the sheet.
  9. Review the Update PDF node to confirm the rename rule uses {{ output.Fecha_Emision }} and {{ output.Numero_Factura }} so files get clear names.
  10. Send a test email to your Gmail with a zip that contains one PDF and one XML invoice. Run the workflow and wait for the poll or trigger a test run.
  11. Check the Google Drive folder for the uploaded PDF and confirm the final name matches the invoice date and number. Then check Google Sheets for a new or updated row.
  12. Troubleshoot common issues: if no items appear, check the Gmail search query and labels; if XML extraction fails, confirm the zip contains valid XML and PDF; if rename fails, confirm Drive permissions; if duplicates appear, verify the Key field formula.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Gmail

Sign up

No cost: Personal Gmail (Gmail API has no usage-based pricing; quotas apply)

Google Drive

Sign up

Drive API: $0 (no additional cost; quota-limited)

Google Sheets

Sign up

Free: $0 (Google Sheets API usage has no additional cost; quota limits apply)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.