Save invoice attachments from Gmail to Drive
Invoices that arrive by email are filed into a Drive folder automatically.
How it works
Trigger: Gmail — new email matching "invoice has:attachment"
- Watch Gmail for emails with "invoice" and an attachment.
- Download the attachments.
- Upload them to a Drive folder named by month, e.g. "Invoices/2026-09".
Diagram
Trigger App Code
Code
JavaScript used in the Code step — already included in the template below.
// Splits every attachment into its own item and gives it a sortable file name:
// 2026-09-26-supplier.com-invoice.pdf
const out = [];
for (const item of $input.all()) {
const date = new Date(item.json.date).toISOString().slice(0, 10);
const sender = item.json.from?.value?.[0]?.address || "unknown@unknown";
const domain = sender.split("@")[1];
for (const file of Object.values(item.binary || {})) {
out.push({
json: { fileName: `${date}-${domain}-${file.fileName}` },
binary: { data: file },
});
}
}
return out;Build it
Pick your tool — same automation, step by step.
Copy and paste straight into an n8n canvas (Ctrl+V), or download and use Import from File. Then connect your own credentials and replace every YOUR_… placeholder.
Show code (116 lines)
{
"name": "Save invoice attachments from Gmail to Drive (Flowngn)",
"nodes": [
{
"parameters": {
"content": "## Save invoice attachments from Gmail to Drive\nInvoices that arrive by email are filed into a Drive folder automatically.\n\n**Setup**\n1. Open each node and connect your own credentials.\n2. Replace every YOUR_… placeholder.\n3. Test once, then activate.\n\nFree template from Flowngn",
"height": 260,
"width": 340
},
"id": "35c47c31-a6eb-42db-a482-bc5e476f5441",
"name": "Setup notes",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
-420,
-60
]
},
{
"parameters": {
"pollTimes": {
"item": [
{
"mode": "everyHour"
}
]
},
"simple": false,
"filters": {
"q": "invoice has:attachment"
},
"options": {
"downloadAttachments": true
}
},
"id": "35c47c31-a6eb-42db-a482-bc5e476f5441",
"name": "Invoice email",
"type": "n8n-nodes-base.gmailTrigger",
"typeVersion": 1.2,
"position": [
0,
0
]
},
{
"parameters": {
"jsCode": "// Splits every attachment into its own item and gives it a sortable file name:\n// 2026-09-26-supplier.com-invoice.pdf\nconst out = [];\n\nfor (const item of $input.all()) {\n const date = new Date(item.json.date).toISOString().slice(0, 10);\n const sender = item.json.from?.value?.[0]?.address || \"unknown@unknown\";\n const domain = sender.split(\"@\")[1];\n\n for (const file of Object.values(item.binary || {})) {\n out.push({\n json: { fileName: `${date}-${domain}-${file.fileName}` },\n binary: { data: file },\n });\n }\n}\n\nreturn out;"
},
"id": "35c47c31-a6eb-42db-a482-bc5e476f5441",
"name": "Split attachments",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
300,
0
]
},
{
"parameters": {
"name": "={{ $json.fileName }}",
"driveId": {
"__rl": true,
"value": "My Drive",
"mode": "list"
},
"folderId": {
"__rl": true,
"value": "YOUR_INVOICES_FOLDER_ID",
"mode": "id"
},
"inputDataFieldName": "data",
"options": {}
},
"id": "35c47c31-a6eb-42db-a482-bc5e476f5441",
"name": "Upload to Drive",
"type": "n8n-nodes-base.googleDrive",
"typeVersion": 3,
"position": [
600,
0
]
}
],
"connections": {
"Invoice email": {
"main": [
[
{
"node": "Split attachments",
"type": "main",
"index": 0
}
]
]
},
"Split attachments": {
"main": [
[
{
"node": "Upload to Drive",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"meta": {
"templateCredsSetupCompleted": false
},
"tags": []
}In Make, create a new scenario and add these modules in order:
- Gmail › Watch Emails (search: invoice has:attachment)
- Tools › Set variable / Iterator + Array aggregator (same logic as the Code step)
- Google Drive › Upload a File
- Every module run uses Make operations — the free plan includes a monthly quota.
- Make's built-in functions (map, sum, formatDate…) can replace most Code steps; for complex logic use a code module.
- Module and step names can differ slightly as Make and Zapier update their apps.
In Zapier, create a new Zap and add these steps in order:
- Gmail — New Email Matching Search (invoice has:attachment)
- Code by Zapier — Run JavaScript (paste the code from the Code section)
- Google Drive — Upload File
- Zaps with more than two steps need a paid Zapier plan.
- Webhooks, Filters/Paths and Code by Zapier are premium features on some Zapier plans.
- Code by Zapier runs JavaScript: reuse the code shown above, reading inputs from inputData instead of $json.
- Module and step names can differ slightly as Make and Zapier update their apps.
Tips
- Rename files as date-sender-originalname so they sort nicely.
Related flows
Finance & AdminMedium
Weekly KPI report by email
Every Monday, get a short summary of last week's key numbers from your sheet.
Google Sheets → Gmail3h/mo
Finance & AdminMedium
Automatic reminders for overdue invoices
Every morning, clients with unpaid overdue invoices get a polite reminder email.
Google Sheets → Gmail4h/mo
Finance & AdminMedium
Monthly revenue report by email
On the 1st of each month, get last month's Stripe revenue compared with the month before.
Stripe → Gmail2h/mo