Receipt/Invoice Organizer (Gmail + Google Drive)
Monitors Gmail for emails with a specific label ("receipts" or "invoices"):
- Validates sender - Checks if the email sender is in a Google Sheets whitelist
- Creates organized folder structure - Sets up Company Name → MM/YYYY folders in Google Drive
- Processes attachments - Extracts all attachments from the email
- Files documents - Uploads each attachment to the appropriate company/month folder with metadata (sender, date received)
Result: Automatically organizes business receipts and invoices into a structured Google Drive filing system
Shared 8/25/2025
197 views
Visual Workflow
JSON Code
{
"meta": {
"instanceId": "125637e355429ab06f8886794f7df9252a3e338f92a1957141a8989e48f2b612"
},
"nodes": [
{
"id": "9adf8a9b-a84c-42ea-8246-1fe3dbb7a4e3",
"name": "Search For Folder",
"type": "n8n-nodes-base.googleDrive",
"position": [
1104,
-112
],
"parameters": {
"filter": {
"folderId": {
"__rl": true,
"mode": "id",
"value": "={{ $json.id }}"
}
},
"options": {},
"resource": "fileFolder",
"queryString": "={{$json.folderName}}"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "qI7DvSNzK02Lcs3f",
"name": "Main Account"
}
},
"typeVersion": 3,
"alwaysOutputData": true
},
{
"id": "58b3085c-6fa8-4f33-b97c-b7c054a580dd",
"name": "Create Month Folder",
"type": "n8n-nodes-base.googleDrive",
"position": [
1552,
-32
],
"parameters": {
"name": "={{ $('MM/YYYY').first().json.folderName }}",
"driveId": {
"__rl": true,
"mode": "list",
"value": "My Drive"
},
"options": {},
"folderId": {
"__rl": true,
"mode": "id",
"value": "={{ $('MM/YYYY').item.json.id }}"
},
"resource": "folder"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "qI7DvSNzK02Lcs3f",
"name": "Main Account"
}
},
"typeVersion": 3
},
{
"id": "a5954523-6df3-45f8-aabd-7ad8856ade5f",
"name": "Check If Folder Exists",
"type": "n8n-nodes-base.if",
"position": [
1328,
-112
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "09b62415-cb8f-478e-b6d3-aa463fe70c81",
"operator": {
"type": "object",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $json }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "b0156be8-037a-4096-aa3e-ab0020cd75f0",
"name": "Gmail Trigger",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-240,
-112
],
"parameters": {
"simple": false,
"filters": {
"labelIds": [
"Label_2362127341197103198"
]
},
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyX",
"unit": "minutes",
"value": 15
}
]
}
},
"credentials": {
"gmailOAuth2": {
"id": "EwXXtt2Nq8R5cHzM",
"name": "Gmail account"
}
},
"typeVersion": 1.2
},
{
"id": "0117408f-8ca1-44cf-9c72-861a1a7ca16c",
"name": "Gmail",
"type": "n8n-nodes-base.gmail",
"position": [
1776,
-112
],
"webhookId": "e62ae049-d968-4e6a-a62d-06963c8e592f",
"parameters": {
"simple": false,
"options": {
"downloadAttachments": true
},
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "get"
},
"credentials": {
"gmailOAuth2": {
"id": "EwXXtt2Nq8R5cHzM",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "3d7657b1-9cca-4221-b749-8071d44f0cda",
"name": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"position": [
2224,
-112
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "224f7e41-f41c-4432-a70c-d5b3a29e5ab6",
"name": "Company Folder Exists",
"type": "n8n-nodes-base.if",
"position": [
432,
-112
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "09b62415-cb8f-478e-b6d3-aa463fe70c81",
"operator": {
"type": "object",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $json }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "47b2c785-4198-4999-b6c5-059d4e7e6a37",
"name": "Create Company Folder",
"type": "n8n-nodes-base.googleDrive",
"position": [
656,
-32
],
"parameters": {
"name": "={{ $('Lookup in Sheets').item.json['Company Name'] }}",
"driveId": {
"__rl": true,
"mode": "list",
"value": "My Drive"
},
"options": {},
"folderId": {
"__rl": true,
"mode": "list",
"value": "1UWEr0q9nOXEoRh48hL3WRLjRKepbuT4D",
"cachedResultUrl": "https://drive.google.com/drive/folders/1UWEr0q9nOXEoRh48hL3WRLjRKepbuT4D",
"cachedResultName": "Receipts/Invoices"
},
"resource": "folder"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "qI7DvSNzK02Lcs3f",
"name": "Main Account"
}
},
"typeVersion": 3
},
{
"id": "793d3710-97c2-4daf-b8a3-3a0f70aa8895",
"name": "Lookup in Sheets",
"type": "n8n-nodes-base.googleSheets",
"position": [
-16,
-112
],
"parameters": {
"options": {},
"filtersUI": {
"values": [
{
"lookupValue": "={{ $('Gmail Trigger').item.json.from.value[0].address }}",
"lookupColumn": "Email"
}
]
},
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Kv01zZyihztd2ESdG54i9utrY1jFDQOKhX-iRITrwWo/edit#gid=0",
"cachedResultName": "Sheet1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1Kv01zZyihztd2ESdG54i9utrY1jFDQOKhX-iRITrwWo",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Kv01zZyihztd2ESdG54i9utrY1jFDQOKhX-iRITrwWo/edit?usp=drivesdk",
"cachedResultName": "Contact Whitelist"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "qVntjW61XxH91qGU",
"name": "Google Sheets account"
}
},
"typeVersion": 4.5,
"alwaysOutputData": false
},
{
"id": "2fb99625-5196-4ead-83bc-2e1a414956f5",
"name": "Search Company Folder1",
"type": "n8n-nodes-base.googleDrive",
"position": [
208,
-112
],
"parameters": {
"filter": {
"whatToSearch": "folders"
},
"options": {},
"resource": "fileFolder",
"queryString": "={{ $('Lookup in Sheets').item.json['Company Name'] }}"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "qI7DvSNzK02Lcs3f",
"name": "Main Account"
}
},
"typeVersion": 3,
"alwaysOutputData": true
},
{
"id": "70eab899-e08d-413a-99d8-16f427ff9120",
"name": "Upload To Folder",
"type": "n8n-nodes-base.googleDrive",
"position": [
2448,
-112
],
"parameters": {
"name": "={{ Date.now();}}-{{ $('Loop Over Items').item.binary.data.fileName }} ",
"driveId": {
"__rl": true,
"mode": "list",
"value": "My Drive",
"cachedResultUrl": "https://drive.google.com/drive/my-drive",
"cachedResultName": "My Drive"
},
"options": {
"ocrLanguage": "en",
"propertiesUi": {
"propertyValues": [
{
"key": "sender",
"value": "={{ $('Gmail').item.json.from.value[0].address }}"
},
{
"key": "time_received",
"value": "={{ $('Gmail').item.json.date }}"
}
]
}
},
"folderId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Search For Folder').first().json.id || $('Create Month Folder').item.json.id }}"
},
"inputDataFieldName": "=data"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "qI7DvSNzK02Lcs3f",
"name": "Main Account"
}
},
"typeVersion": 3
},
{
"id": "27569128-95c1-4369-a182-11114506594d",
"name": "Split Up Binary Data",
"type": "n8n-nodes-base.code",
"position": [
2000,
-112
],
"parameters": {
"jsCode": "// Get all input items from previous node\nconst inputItems = $input.all();\nconst outputResults = [];\n\n// Process each input item\nfor (const inputItem of inputItems) {\n // Check if item has binary data\n if (inputItem.binary) {\n // Process each binary file in the item\n for (const binaryKey of Object.keys(inputItem.binary)) {\n const binaryFile = inputItem.binary[binaryKey];\n \n // Create a separate output item for each binary file\n outputResults.push({\n json: {\n fileName: binaryFile.fileName,\n mimeType: binaryFile.mimeType,\n fileSize: binaryFile.fileSize,\n originalBinaryKey: binaryKey // Add this for reference\n },\n binary: {\n data: binaryFile // Keep the binary data\n }\n });\n }\n } else {\n console.log('No binary data found in item');\n }\n}\n\nreturn outputResults;"
},
"typeVersion": 2
},
{
"id": "e8cf18fd-9e88-478d-ac68-c1bafe1ea24d",
"name": "MM/YYYY",
"type": "n8n-nodes-base.set",
"position": [
880,
-112
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "143b3b94-a8d7-46b6-8ea8-2e70c082f5b1",
"name": "=folderName",
"type": "string",
"value": "={{\nString(new Date($('Gmail Trigger').item.json.date).getUTCMonth() + 1).padStart(2, '0')\n + '/' + \n new Date($('Gmail Trigger').item.json.date).getUTCFullYear()\n}}\n"
}
]
},
"includeOtherFields": true
},
"typeVersion": 3.4
}
],
"pinData": {},
"connections": {
"Gmail": {
"main": [
[
{
"node": "Split Up Binary Data",
"type": "main",
"index": 0
}
]
]
},
"MM/YYYY": {
"main": [
[
{
"node": "Search For Folder",
"type": "main",
"index": 0
}
]
]
},
"Gmail Trigger": {
"main": [
[
{
"node": "Lookup in Sheets",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "Upload To Folder",
"type": "main",
"index": 0
}
]
]
},
"Lookup in Sheets": {
"main": [
[
{
"node": "Search Company Folder1",
"type": "main",
"index": 0
}
]
]
},
"Upload To Folder": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Search For Folder": {
"main": [
[
{
"node": "Check If Folder Exists",
"type": "main",
"index": 0
}
]
]
},
"Create Month Folder": {
"main": [
[
{
"node": "Gmail",
"type": "main",
"index": 0
}
]
]
},
"Split Up Binary Data": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Company Folder Exists": {
"main": [
[
{
"node": "MM/YYYY",
"type": "main",
"index": 0
}
],
[
{
"node": "Create Company Folder",
"type": "main",
"index": 0
}
]
]
},
"Create Company Folder": {
"main": [
[
{
"node": "MM/YYYY",
"type": "main",
"index": 0
}
]
]
},
"Check If Folder Exists": {
"main": [
[
{
"node": "Gmail",
"type": "main",
"index": 0
}
],
[
{
"node": "Create Month Folder",
"type": "main",
"index": 0
}
]
]
},
"Search Company Folder1": {
"main": [
[
{
"node": "Company Folder Exists",
"type": "main",
"index": 0
}
]
]
}
}
}