Tip: Set up a dedicated email filter in Gmail to label invoice emails for easier tracking.
Automatically Extract Invoice Data from Email and Save to Google Sheets
What You'll Have When Done: Automatically capture invoice attachments from Gmail, extract all key information using PDF.co Document Parser, and populate a Google Sheets with invoice details.
Prerequisites
Before you begin, make sure you have:
- A PDF.co API Key (Get yours here)
- A Gmail account with OAuth2 credentials configured in n8n
- A Google Sheets account with OAuth2 credentials in n8n
- An n8n instance (cloud or self-hosted)
- A Google Sheets document set up to save invoice data (Sample here)
- A custom Document Parser Template (Create here)
Quick Start Options
Option A: I Want It Working Now
- Import this workflow template → Download JSON File
- Connect your Gmail, PDF.co, and Google Sheets accounts
- Set up the Gmail node filter for invoice emails
- Configure your Google Sheets document
- Create a custom Document Parser template
- Test with sample invoice emails
- Activate and let it run
Option B: I Want to Build It Step-by-Step
Follow the 5-step guide below to create the automation from scratch.
What This Automation Does (Overview)
- Monitors Gmail for new emails with invoice attachments
- Uploads PDF attachments to PDF.co for processing
- Parses invoice data using PDF.co's Document Parser
- Saves all invoice details to a Google Sheets tracker
Step 1: Monitor Gmail for Invoice Emails
Node: Gmail Trigger
Settings:
- Simple: False (use advanced filters)
- Filters:
- Query:
has:attachment subject:New Invoice
- Query:
- Options:
- Download Attachments: True
Customize Your Email Filter: Adjust the Gmail query to match your invoice emails:
has:attachment subject:Invoice
- Emails with "Invoice" in subjecthas:attachment from:accounting@company.com
- Specific sender
Success Looks Like: The trigger activates when matching emails arrive, automatically downloading PDF attachments for processing.
Step 2: Upload Invoice to PDF.co
Node: PDF.co → Upload File
Settings:
- Binary File:
True
- Input Binary Field:
attachment_0
- File Name:
SampleInvoice.pdf
(or use dynamic naming)
Success Looks Like: The PDF attachment is uploaded to PDF.co's cloud storage, returning a file URL for processing.
Note: Learn more about File Upload in the PDF.co Documentation
Step 3: Parse Invoice Data
Node: HTTP Request → PDF.co Document Parser
Settings:
- Method: POST
- URL:
https://api.pdf.co/v1/pdf/documentparser
- Headers:
x-api-key
: Your PDF.co API keyContent-Type
: application/json
- Body Parameters:
url
:={{ $json.url }}
(from upload step)templateId
:1
(your document parser template ID)inline
:true
Document Parser Template Setup:
- Create Template: Use PDF.co's Template Editor to define extraction fields
- Common Fields:
- Company Name (vendor)
- Customer Name
- Invoice ID
- Date Issued
- Total Amount
- Line item tables
- Test Template: Use sample invoices to refine extraction accuracy (Sample here)
Success Looks Like: The parser returns structured JSON with extracted invoice fields and table data.
Note: Learn more about Document Parser in the PDF.co Documentation
Step 4: Process and Structure Data
Node: Code (JavaScript)
Purpose: Transform the parsed invoice data into a format suitable for Google Sheets, handling line items and field mapping.
Key Functions:
- Extract Invoice Fields: Company names, dates, invoice IDs, totals
- Process Line Items: Handle table data with quantities, descriptions, prices
- Data Transformation: Convert types and structure for spreadsheet format
Success Looks Like: Each line item becomes a separate row with all invoice header information included.
Step 5: Log to Google Sheets
Node: Google Sheets → Append Row
Settings:
- Document From List: Your Google Sheets document
- Sheet From List: Your target sheet (e.g., "Sheet1")
- Column Mappings:
- Vendor:
={{ $json.companyName }}
- Customer:
={{ $json.companyName2 }}
- Invoice ID:
={{ $json.invoiceId }}
- Invoice Date:
={{ $json.dateIssued }}
- Quantity:
={{ $json.column1 }}
- Description:
={{ $json.column2 }}
- Unit Price:
={{ $json.column3 }}
- Total:
={{ $json.column4 }}
- Grand Total:
={{ $json.total }}
- Vendor:
Spreadsheet Setup: Get a copy of the Sample Google Sheets here
Success Looks Like: Each processed invoice creates new rows in your spreadsheet with all extracted data properly formatted.
Congrats! You've built a complete invoice processing automation that eliminates manual data entry and ensures accurate tracking.
Built something cool? Share it with us @pdfdotco
Related Tutorials



