This is Part 1 of the “Restaurant PO Automation” series. The series guide and case study established the client brief, the fictional Harbour Kitchen data set, and the five-node architecture we build against. This post starts at node 01 and solves one problem: capturing the right purchase-order email in Gmail and getting its PDF attachment into n8n as a binary file the downstream nodes can actually read.
Series guide: Restaurant Purchase Order Automation: Series Guide & Case Study
1. What the client actually needs
A Singapore warehouse operator receives purchase orders by email from restaurants of the same brand but different outlets. The goods cover fresh produce, protein, frozen items and dry goods. Every email carries a PDF, and the manual job is to open it, read the PO number and quantities, and type them into Google Sheets for daily dispatch. The client wants every order, from whichever outlet, recorded automatically in Sheets and labelled with that outlet. Volume is not the problem; repetition and the risk of mixing up two outlets buying the same SKU are. We treat this as a data-capture problem first: nothing downstream can be trusted until the email and its attachment are captured correctly.
2. Why the trigger decides the whole workflow
The trigger is the only node that ever sees the mailbox. Everything after it consumes whatever the trigger emits, so a single setting here decides whether the rest of the workflow is possible at all. If the trigger returns only message metadata, there is no file payload and we must add a second Gmail node to fetch the attachment by message ID. If the trigger downloads the attachment itself, we pass that binary straight to Extract From File and keep the build small.
That is why we settled on five main nodes: Gmail Trigger, Extract From File, Information Extractor, Code, and Google Sheets. The AI Chat Model is a sub-node underneath Information Extractor, not a sixth main node. Each extra node is another credential, another API call, and another place where a field name can drift. A precisely filtered trigger that also returns binary removes two classes of work: downstream noise filtering, and a separate fetch step. We describe the running workflow, not discarded sketches, because it is the single source of truth.
3. Configuring Gmail Trigger
We create a workflow named Demo 04 | Restaurant PO Processing Automation, add Gmail Trigger as the first step, and select the connected Gmail account as the credential. The parameters follow.
| Parameter | Value | Purpose |
|---|---|---|
| Credential | Connected Gmail account for the receiving mailbox | Authorises polling |
| Poll Times | Every Minute | Short interval for testing; verify a slower interval before production |
| Event | Message Received | Fires on newly received mail, not on a scan of historical mail |
| Simplify | OFF | Keeps the full message structure and attachment handling available |
| Read Status | Unread and read emails | Prevents a demo test email from disappearing once opened |
| Search | has:attachment filename:pdf subject:"Purchase Order" | Restricts polling to relevant mail |
The Search value is plain Gmail search syntax, not an n8n expression:
has:attachment filename:pdf subject:"Purchase Order"
It reads as three conditions applied together: the message must have an attachment, that attachment must be a PDF, and the subject must contain “Purchase Order”. This is our first line of defence against everyday mail starting an execution. A tight filter is also a cost control, since a Gmail trigger polls on a schedule rather than reacting to a webhook: fewer irrelevant executions mean fewer downstream model calls.

4. Why “Unread and read emails” matters in a demo
Read Status is the setting that quietly breaks a demonstration. The intuitive choice is unread mail only, on the assumption that an unread message is a new order. In practice, we open the test email in Gmail to confirm the attachment and subject line; opening it marks the message as read. With unread-only polling, a subsequent Fetch Test Event returns nothing, and the failure looks like a broken credential or a bad filter when it is neither.
Selecting “Unread and read emails” removes that trap. We can open, re-open and re-fetch the same message as often as we need. It is deliberately a demo setting. A production workflow would combine unread-only polling with a “processed” label or an idempotency check on the PO number; that is duplicate-order handling, which this demo does not include. We mark it as phase two.
5. Sending one test email
We save the workflow, start the trigger listening (Fetch Test Event or Listen for Test Event, depending on the n8n version), and only then send a test message from a second mailbox to the connected Gmail account. The trigger fires on mail arriving while it is watching, so sending earlier produces an empty test event.
The test message uses this subject and one attachment:
Subject: Purchase Order - Orchard Outlet - PO-20261123-001
Attachment: PO-20261123-001.pdf
We attach exactly one PDF per email. The full exercise uses four simulated PDFs - PO-20261123-001.pdf through PO-20261123-004.pdf, one each for the Orchard, Marina Bay, Jurong East and Tampines outlets of the fictional Harbour Kitchen brand, five line items each, twenty order lines in total, ten per delivery date. Four attachments in one mail would force us to build multi-attachment splitting into this first version. One PDF per email keeps the output to a single binary item; multi-attachment handling is phase two, to verify against real supplier behaviour.

6. Reading the first output: JSON metadata is not the PDF
With Download Attachments off - the default state - the trigger output looks convincing and is still not what we need. It returns one item of JSON metadata: the message id 1a1f958887756d98, a block of headers, the labelIds array, and a sizeEstimate. Those confirm the Gmail connection works, the Search filter matched, and exactly one message was retrieved. They do not contain the PDF.
This is the gotcha worth remembering. Headers describe the envelope; labelIds describe Gmail’s classification; sizeEstimate is a number, not a file. There is no binary property, so Extract From File would have nothing to point at. The distinction is between knowing an email has a PDF and holding the PDF bytes; only the second can be parsed.

7. Download Attachments and the five-node workflow
The fix is one option on the same node: Options -> Add option -> Download Attachments, set to ON. We leave Attachment Prefix at its default attachment_. No other Gmail node is required.

Re-running Fetch Test Event produces a Binary view alongside the JSON:
| Field | Value |
|---|---|
| Binary Property | attachment_0 |
| File Name | PO-20261123-001.pdf |
| MIME Type | application/pdf |
| File Size | 93.9 KB |
| Items | 1 |
Because the trigger returns the PDF binary directly, the originally planned “Gmail Get Message” node is unnecessary: it would have taken the message id, fetched the full message again and enabled attachment download - extra work to obtain a file we already hold. This is also where the design changed from seven nodes to five. The earliest sketch listed Gmail Trigger, Gmail Get Message, Extract From File, AI Information Extractor, Code, Google Sheets, and a Gmail Add Label step. Download Attachments removed the second node; the demo boundary removed the label step, because labelling exists to support duplicate handling and this demo has none.

The final running workflow is therefore:
01 Gmail Trigger -> filtered mail + binary attachment_0
02 Extract From File -> PDF text
03 Information Extractor -> structured order JSON
(AI Chat Model sub-node)
04 Code -> one row per order line
05 Google Sheets -> appended order lines
To be explicit about scope: this is a demo, not a production warehouse system. There is no duplicate-order handling, no revised-PO logic, no exception review, no Airtable, no inventory deduction, and no dispatch confirmation emails. We stop at five nodes. Each omission is a separate decision in a real deployment.
8. Verification checklist
Before moving on, we confirm node 01 against the following table, checking the actual execution output rather than the green “success” badge.
| Check | Expected | Result |
|---|---|---|
| Trigger fires on the test email | 1 item | Pass |
| Search filter applied | has:attachment filename:pdf subject:"Purchase Order" | Pass |
| Read Status | Unread and read emails | Pass |
| Download Attachments | ON, prefix attachment_ default | Pass |
| Binary property present | attachment_0 | Pass |
| File name | PO-20261123-001.pdf | Pass |
| MIME type | application/pdf | Pass |
| File size | 93.9 KB | Pass |
| Second Gmail node needed | No | Pass |
| Main node count | 5 | Pass |
One practical note: n8n shows Schema, Table and JSON views for the output panel. The binary payload appears in the Binary view; if the panel stays on Schema, we switch views rather than assume the attachment is missing. A wrong prefix or file type would fail at node 02 with a less obvious error.
9. What this node does not handle
The trigger assumes a narrow, well-behaved input.
First, scanned or image-only PDFs. Our four simulated PDFs are text-type PDFs exported from WPS. A scanned purchase order contains no extractable text layer and would need OCR or a vision-capable model. Whether a real supplier sends text-type or scanned PDFs is the first thing to verify with real samples; we implement neither path here.
Second, multiple attachments in one email. We send one PDF per mail by design. If a supplier bundles a PO, a delivery note and a spec sheet in one message, the trigger produces several binary items and the workflow would need a splitting and classification step - phase two, to verify against real mail patterns.
Third, duplicate mail and revised POs. A customer who re-sends an order, or sends a corrected version, simply produces another execution and another set of rows. There is no idempotency key, no processed label, and no comparison against previously recorded PO numbers. In production this would be the first thing to add.
Finally, nothing here validates the sender, confirms the attachment is really a purchase order, or routes an unreadable file to a human. Those are exception-review features. The trigger’s job ends when it hands over a binary PDF; in Part 2 we pass attachment_0 to Extract From File.
Data note: all business data in this series - Harbour Kitchen, its outlets, PO numbers, SKUs, quantities and delivery dates - is fictional mock data created for a tutorial. When shown in a portfolio, label it Self-initiated Demonstration. This is a demo, not a production warehouse system.




