Gmail to Google Sheets, purchase orders logged clean
Purchase orders arrive in email, then disappear into someone’s inbox. Later, you’re chasing missing line items, retyping totals, and trying to prove what was actually requested.
This Gmail Sheets orders automation hits ops managers first (because they feel the chaos daily), but procurement leads and agency-side client ops folks end up dealing with the same mess. Instead of manual copy-paste, you get one running spreadsheet that stays complete and consistent.
You’ll see how the workflow scans unread PO emails, uses AI to extract the details, then appends clean rows into Google Sheets so your team can finally trust the log.
How This Automation Works
Here’s the complete workflow you’ll be setting up:
n8n Workflow Template: Gmail to Google Sheets, purchase orders logged clean
flowchart LR
subgraph sg0["AI Agent Flow"]
direction LR
n0@{ icon: "mdi:message-outline", form: "rounded", label: "Get many messages", pos: "b", h: 48 }
n1@{ icon: "mdi:cog", form: "rounded", label: "Cron", pos: "b", h: 48 }
n2@{ icon: "mdi:swap-horizontal", form: "rounded", label: "If", pos: "b", h: 48 }
n3@{ icon: "mdi:robot", form: "rounded", label: "AI Agent", pos: "b", h: 48 }
n4@{ icon: "mdi:brain", form: "rounded", label: "Google Gemini Chat Model", pos: "b", h: 48 }
n5@{ icon: "mdi:swap-vertical", form: "rounded", label: "Set final output keys", pos: "b", h: 48 }
n6@{ icon: "mdi:swap-horizontal", form: "rounded", label: "Filter emails", pos: "b", h: 48 }
n7["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/code.svg' width='40' height='40' /></div><br/>Reformatted to upload in Goo.."]
n8@{ icon: "mdi:database", form: "rounded", label: "Get row(s) in sheet in Googl..", pos: "b", h: 48 }
n9@{ icon: "mdi:database", form: "rounded", label: "Append row in sheet", pos: "b", h: 48 }
n2 --> n5
n1 --> n0
n3 --> n7
n6 --> n2
n0 --> n6
n5 --> n3
n4 -.-> n3
n8 -.-> n3
n7 --> n9
end
%% Styling
classDef trigger fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
classDef ai fill:#e3f2fd,stroke:#1976d2,stroke-width:2px
classDef aiModel fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px
classDef decision fill:#fff8e1,stroke:#f9a825,stroke-width:2px
classDef database fill:#fce4ec,stroke:#c2185b,stroke-width:2px
classDef api fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef code fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
classDef disabled stroke-dasharray: 5 5,opacity: 0.5
class n3 ai
class n4 aiModel
class n2,n6 decision
class n8,n9 database
class n7 code
classDef customIcon fill:none,stroke:none
class n7 customIcon
Why This Matters: Purchase Orders Get Lost in Email
PO email handling looks “fine” right up until it isn’t. One person is out sick, a supplier changes their template, or someone forwards a request without the attachment. Then the spreadsheet doesn’t match the inbox, the inbox doesn’t match what was shipped, and you’re stuck reconstructing the truth from scattered threads. Worse, every manual re-entry creates a fresh chance to misread a quantity, drop a SKU, or log the wrong requested date. It’s not dramatic. It’s just constant.
The friction compounds. Here’s where it usually breaks down.
- Someone has to read every “PO” email, decide if it counts, then retype the same fields into a sheet.
- Forwarded requests and inconsistent subject lines cause “missed” orders that only show up when you’re already late.
- Attachments make it slower because you’re opening PDFs, scanning for totals, then guessing the right column to paste into.
- Even when the team does it right, the spreadsheet ends up formatted differently by different people, which makes reporting painful.
What You’ll Build: Gmail → AI Extraction → Sheets Log
This workflow runs on a schedule and watches your Gmail inbox for unread purchase order emails. When it finds one, it checks that the subject line matches what you consider a “real” PO, then it gathers the key content (and can handle attachments when present). Next, an AI agent (backed by Google Gemini in this workflow) reads the email text and extracts structured order details like supplier, items, quantities, and dates. Those extracted fields get normalized into a consistent schema, including converting dates into ISO calendar weeks for cleaner planning. Finally, the workflow formats everything into a row and appends it to your Google Sheet, so you get a growing purchase order log without overwriting anything.
The workflow starts with a timed inbox check using Cron. From there, Gmail messages are filtered, then AI turns messy email content into reliable fields. Google Sheets receives a new appended row for each order, creating a single source of truth you can sort, share, and report on.
What You’re Building
| What Gets Automated | What You’ll Achieve |
|---|---|
|
|
Expected Results
Say your team receives 20 purchase orders per week. If each one takes about 6 minutes to open, read, copy fields, and paste into Google Sheets, that’s roughly 2 hours of admin time weekly (and that’s assuming no corrections later). With this workflow, the “work” is basically letting it run: emails get picked up on the next minute, extracted, then appended automatically. You’ll still spot-check a few, but the repetitive logging is gone.
Before You Start
- n8n instance (try n8n Cloud free)
- Self-hosting option if you prefer (Hostinger works well)
- Gmail for fetching unread purchase order emails.
- Google Sheets to store your purchase order log.
- Google Gemini (PaLM) API credentials (get it from Google AI Studio / Gemini API in Google Cloud).
Skill level: Beginner. You’ll connect accounts, adjust a subject filter, and confirm your sheet headers match the workflow fields.
Want someone to build this for you? Talk to an automation expert (free 15-minute consultation).
Step by Step
A scheduled inbox check kicks it off. A Cron trigger runs every minute, then the workflow pulls a batch of unread Gmail messages so nothing sits unseen for hours.
Only relevant emails move forward. A subject-line filter screens out noise (like shipping notifications or generic vendor emails), and an attachment check decides how to handle messages that include PDFs versus plain text.
AI extracts order details into a predictable format. The workflow sends the email content into an AI agent powered by Google Gemini, which returns structured fields you can actually store and report on, not a loose summary.
Google Sheets becomes the system of record. The workflow formats dates into ISO calendar weeks, shapes the output into a row, optionally looks up related product data in Sheets, then appends the final record so your log keeps growing cleanly.
You can easily modify the subject rules to match your vendors, or change the output columns to fit your internal PO schema. See the full implementation guide below for customization options.
Step-by-Step Implementation Guide
Step 1: Configure the Scheduled Trigger
This workflow runs on a schedule and starts by checking Gmail for new unread emails.
- Add the Scheduled Trigger node and open its settings.
- Set Trigger Times to run at
08:00(hour8). - Connect Scheduled Trigger to Fetch Email Batch.
Step 2: Connect Gmail and filter the email batch
Pull unread emails from the last 24 hours and filter by specific subject keywords before processing attachments.
- Open Fetch Email Batch and set Operation to
getAll. - Set Limit to
100and Simple tofalse. - Configure Filters → Read Status to
unreadand Filters → Received After to{{ $today.minus({ days: 1 }).toISODate() }}. - Enable Options → Download Attachments to
true. - Credential Required: Connect your Gmail credentials.
- Open Filter Subject Lines and set two conditions with Left Value as
{{ $json.subject }}and Right Value asMarketingandBuchungsanfrage(OR combinator). - Connect Fetch Email Batch → Filter Subject Lines → Attachment Check.
Step 3: Validate attachments and define output schema
Ensure emails have attachments and define the fields the AI should produce.
- In Attachment Check, set the condition Left Value to
{{ $('Filter Subject Lines').item.binary }}with Operationexists. - Connect the true output of Attachment Check to Define Output Fields.
- In Define Output Fields, add the array field final_json_keys with the value
[ "Laufende Nummer", "Lieferant", "Lieferanten-Nr", "Marke", "Marken-Nr", "Kalenderwoche\nStart", "Kalenderwoche\nEnde", "Marketing Status", "Paket", "Produkt", "Länder-Aktivierung", "Kosten" ]. - Connect Define Output Fields to Order Extraction Agent.
Step 4: Set up the AI extraction flow
The AI agent reads the email text, enriches products using Sheets, and returns a structured JSON array.
- Open Order Extraction Agent and confirm the Text prompt includes the input reference
{{ $('Attachment Check').item.json.text }}. - Ensure the output format section returns only the JSON array as defined in the prompt.
- Open Gemini Chat Engine and connect it as the language model for Order Extraction Agent (AI Language Model connection).
- Credential Required: Connect your Google Gemini (PaLM) credentials in Gemini Chat Engine.
- Open Lookup Sheet Rows and select your Document ID and Sheet Name for product lookup.
- Credential Required: Connect your Google Sheets credentials in Order Extraction Agent (the Lookup Sheet Rows tool uses the parent agent credentials).
Step 5: Parse AI output and append to Google Sheets
The workflow converts the AI JSON output into rows and appends them to your spreadsheet.
- Open Format Rows for Sheets and keep the JavaScript that parses
item.json.outputinto separate JSON objects. - Connect Order Extraction Agent → Format Rows for Sheets → Append Sheet Row.
- In Append Sheet Row, set Operation to
append. - Select the target Document ID and Sheet Name for writing results.
- Credential Required: Connect your Google Sheets credentials.
Step 6: Test and Activate Your Workflow
Run a manual test to confirm emails are parsed and rows are added to your sheet, then activate for daily processing.
- Click Execute Workflow and verify that Fetch Email Batch returns unread emails.
- Confirm Filter Subject Lines and Attachment Check allow valid emails through.
- Inspect Order Extraction Agent output to ensure it returns a valid JSON array.
- Verify Append Sheet Row adds new rows to your sheet.
- Toggle the workflow to Active to enable scheduled runs.
Troubleshooting Tips
- Gmail credentials can expire or need specific permissions. If things break, check the Gmail node’s connected account in n8n credentials first.
- If you’re using Wait nodes or external rendering, processing times vary. Bump up the wait duration if downstream nodes fail on empty responses.
- Default prompts in AI nodes are generic. Add your brand voice early or you’ll be editing outputs forever.
Quick Answers
About 30 minutes if your Gmail, Sheets, and Gemini accounts are ready.
No. You’ll mostly connect credentials and confirm your Google Sheet headers match the fields being appended.
Yes. n8n has a free self-hosted option and a free trial on n8n Cloud. Cloud plans start at $20/month for higher volume. You’ll also need to factor in Google Gemini API usage costs, which are usually small for a typical PO email volume.
Two options: n8n Cloud (managed, easiest setup) or self-hosting on a VPS. For self-hosting, Hostinger VPS is affordable and handles n8n well. Self-hosting gives you unlimited executions but requires basic server management.
Yes, and you should. Most teams start by adjusting the “Filter Subject Lines” rules, then tweak “Define Output Fields” to match their PO columns. If your vendors send PDFs, you can lean more on the attachment path and extraction prompt. You can also point “Append Sheet Row” to a different tab for each department (Ops, Finance, Projects) without changing the rest of the flow.
Usually it’s expired OAuth access or the Gmail account changed its security settings. Reconnect the Gmail credentials in n8n, then re-run a single test execution to confirm it can list unread emails. Also check mailbox permissions if this is a shared inbox, because “works for me” is common here. If you’re pulling a big batch at once, Gmail can throttle requests, so reducing batch size can help.
A typical small team can process dozens to a few hundred PO emails a day with this setup, as long as your AI/API limits support it.
Often, yes for PO extraction. n8n makes it easier to combine filters, AI extraction, and formatting logic in one workflow without paying extra for every branch. The Google Sheets append behavior is straightforward, and you can self-host for unlimited executions if volume spikes. Zapier or Make can still be fine for basic “email to row” use cases, but they get awkward once you’re handling attachments and structured extraction. If you’re torn, Talk to an automation expert and we’ll map the simplest option for your real inbox.
Once this is running, purchase orders stop living in scattered threads and start showing up as clean rows your team can act on. Set it up once, then get back to work that actually moves the business.
Need Help Setting This Up?
Our automation experts can build and customize this workflow for your specific needs. Free 15-minute consultation—no commitment required.