Workflow: Googledrive Workflow
Integrations: function, gmail, gmailTrigger, googleDrive, googleSheets, if, set, splitInBatches, stickyNote, stopAndError

{"meta": {"instanceId": "workflow-e937854a", "versionId": "1.0.0", "createdAt": "2025-09-29T07:07:45.472291", "updatedAt": "2025-09-29T07:07:45.472323", "owner": "n8n-user", "license": "MIT", "category": "automation", "status": "active", "priority": "high", "environment": "production"}, "nodes": [{"id": "13188ea7-7e66-4955-89d0-82ba4dc08dc9", "name": "Search For Folder", "type": "n8n-nodes-base.googleDrive", "position": [-2420, 500], "parameters": {"filter": {"folderId": {"__rl": true, "mode": "id", "value": "={{ $json.id }}"}}, "options": {}, "resource": "fileFolder", "queryString": "={{$json.folderName}}"}, "credentials": {"googleDriveOAuth2Api": {"id": "VypmUgEf64twpmiZ", "name": "Google Drive account"}}, "typeVersion": 3, "alwaysOutputData": true, "notes": "This googleDrive node performs automated tasks as part of the workflow."}, {"id": "ed2ababb-7022-43e1-b638-0132c08ef701", "name": "Create Month Folder", "type": "n8n-nodes-base.googleDrive", "position": [-2060, 680], "parameters": {"name": "={{ $('YYYY/MM').first().json.folderName }}", "driveId": {"__rl": true, "mode": "list", "value": "My Drive"}, "options": {}, "folderId": {"__rl": true, "mode": "id", "value": "={{ $('YYYY/MM').item.json.id }}"}, "resource": "folder"}, "credentials": {"googleDriveOAuth2Api": {"id": "VypmUgEf64twpmiZ", "name": "Google Drive account"}}, "typeVersion": 3, "notes": "This googleDrive node performs automated tasks as part of the workflow."}, {"id": "f5f2365d-0977-48b1-bd2e-29b7707839d9", "name": "Check If Folder Exists", "type": "n8n-nodes-base.if", "position": [-2240, 500], "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, "notes": "This if node performs automated tasks as part of the workflow."}, {"id": "c27b0a9d-8ee2-4eae-963c-14256ffae0b8", "name": "Gmail Trigger", "type": "n8n-nodes-base.gmailTrigger", "position": [-4400, 780], "parameters": {"simple": false, "filters": {"labelIds": ["Label_2"]}, "options": {}, "pollTimes": {"item": [{"mode": "everyX", "unit": "minutes", "value": 15}]}}, "credentials": {"gmailOAuth2": {"id": "HI2iZSvhvC5XOdpp", "name": "Gmail account 2"}}, "typeVersion": 1.2, "notes": "This gmailTrigger node performs automated tasks as part of the workflow."}, {"id": "3eac8c53-1b20-4511-9f2a-f5e838ca0fa0", "name": "Gmail", "type": "n8n-nodes-base.gmail", "position": [-1720, 460], "webhookId": "e62ae049-d968-4e6a-a62d-06963c8e592f", "parameters": {"simple": false, "options": {"downloadAttachments": true}, "messageId": "={{ $('Gmail Trigger').item.json.id }}", "operation": "get"}, "credentials": {"gmailOAuth2": {"id": "HI2iZSvhvC5XOdpp", "name": "Gmail account 2"}}, "typeVersion": 2.1, "notes": "This gmail node performs automated tasks as part of the workflow."}, {"id": "bfae9bb5-6915-4968-8b5e-e72dd46bda55", "name": "Split Up Binary Data1", "type": "n8n-nodes-base.function", "position": [-1560, 460], "parameters": {"functionCode": "let results = [];\n\nfor (item of items) {\n    for (key of Object.keys(item.binary)) {\n        results.push({\n            json: {\n                fileName: item.binary[key].fileName\n            },\n            binary: {\n                data: item.binary[key],\n            }\n        });\n    }\n}\n\nreturn results;"}, "typeVersion": 1, "notes": "This function node performs automated tasks as part of the workflow."}, {"id": "baf55ab9-511f-4404-a2cc-b1c848f6f5c5", "name": "Note2", "type": "n8n-nodes-base.stickyNote", "position": [-1800, 280], "parameters": {"color": 7, "width": 920, "height": 660, "content": "## Upload attachments to Drive\nIncoming files are split up into individual items, each with a single binary data object under the `data` key.\nFiles names are prefixed with the current timestamp"}, "typeVersion": 1, "notes": "This stickyNote node performs automated tasks as part of the workflow."}, {"id": "5d706d3a-db17-4f5f-9eac-ba91c470dbdd", "name": "YYYY/MM", "type": "n8n-nodes-base.set", "position": [-2600, 500], "parameters": {"options": {}, "assignments": {"assignments": [{"id": "143b3b94-a8d7-46b6-8ea8-2e70c082f5b1", "name": "=folderName", "type": "string", "value": "={{\n  new Date($('Gmail Trigger').item.json.date).getUTCFullYear() \n  + '/' + \n  String(new Date($('Gmail Trigger').item.json.date).getUTCMonth() + 1).padStart(2, '0')\n}}\n"}]}, "includeOtherFields": true}, "typeVersion": 3.4, "notes": "This set node performs automated tasks as part of the workflow."}, {"id": "b20a3833-f648-454d-999b-d799727e18e8", "name": "Loop Over Items", "type": "n8n-nodes-base.splitInBatches", "position": [-1320, 460], "parameters": {"options": {}}, "typeVersion": 3, "notes": "This splitInBatches node performs automated tasks as part of the workflow."}, {"id": "bb8c0d21-de74-4abf-bf6c-5eef3f301513", "name": "Note3", "type": "n8n-nodes-base.stickyNote", "position": [-2680, 280], "parameters": {"color": 7, "width": 820, "height": 660, "content": "# Checks if YYYY/MM Folder exists\n## If the directory doesn't exist it is created"}, "typeVersion": 1, "notes": "This stickyNote node performs automated tasks as part of the workflow."}, {"id": "40971ca3-91d3-4651-8137-e973dbd2dbbd", "name": "Company Folder Exists", "type": "n8n-nodes-base.if", "position": [-3180, 500], "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, "notes": "This if node performs automated tasks as part of the workflow."}, {"id": "086ff643-ca10-46ec-92b5-8a014fd3bf3f", "name": "Create Company Folder", "type": "n8n-nodes-base.googleDrive", "position": [-2920, 620], "parameters": {"name": "={{ $('Lookup in Sheets').item.json.company }}", "driveId": {"__rl": true, "mode": "list", "value": "My Drive"}, "options": {}, "folderId": {"__rl": true, "mode": "list", "value": "18ry0AUtrpp3re6u3zQvvs0BQUGFmBKN9", "cachedResultUrl": "{{ $env.WEBHOOK_URL }}", "cachedResultName": "Invoices"}, "resource": "folder"}, "credentials": {"googleDriveOAuth2Api": {"id": "VypmUgEf64twpmiZ", "name": "Google Drive account"}}, "typeVersion": 3, "notes": "This googleDrive node performs automated tasks as part of the workflow."}, {"id": "7792afb7-61d9-402f-814b-f4625cd012bc", "name": "Note4", "type": "n8n-nodes-base.stickyNote", "position": [-3500, 120], "parameters": {"color": 7, "width": 760, "height": 820, "content": "# Checks if a folder with the company of the email exists\n## If it doesn't the directory is created"}, "typeVersion": 1, "notes": "This stickyNote node performs automated tasks as part of the workflow."}, {"id": "1f61ea45-49e6-4018-91ad-2144c1bbc19a", "name": "Sticky Note4", "type": "n8n-nodes-base.stickyNote", "position": [-4120, 280], "parameters": {"color": 6, "width": 560, "height": 660, "content": "# 2. Google Sheets Whitelist Config\n\n## To filter contacts against a whitelist:\n### 1. Make a copy of [this spreadsheet]({{ $env.WEBHOOK_URL }}\n**OR** create a Google Sheet with two columns:\n| **email**     | **company**      |\n\n\n### 2. Add whitelisted emails and their company as rows in the sheet and configure this node **Document** and **Sheet** to point to it.\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, "typeVersion": 1, "notes": "This stickyNote node performs automated tasks as part of the workflow."}, {"id": "f7009cc2-8194-40c9-98e9-edc4a29c5ce8", "name": "Lookup in Sheets", "type": "n8n-nodes-base.googleSheets", "position": [-3900, 780], "parameters": {"options": {}, "filtersUI": {"values": [{"lookupValue": "={{ $('Gmail Trigger').item.json.from.value[0].address }}", "lookupColumn": "email"}]}, "sheetName": {"__rl": true, "mode": "list", "value": "gid=0", "cachedResultUrl": "{{ $env.WEBHOOK_URL }}", "cachedResultName": "Sheet1"}, "documentId": {"__rl": true, "mode": "list", "value": "1gZE7EbLJqfMzQlPoCgE0eeqee_F1Lh9eIwhHsVmYKdw", "cachedResultUrl": "{{ $env.WEBHOOK_URL }}", "cachedResultName": "Contacts Whitelist"}}, "credentials": {"googleSheetsOAuth2Api": {"id": "63dUs6P8a2b5ed5J", "name": "Google Sheets account"}}, "typeVersion": 4.5, "alwaysOutputData": false, "notes": "This googleSheets node performs automated tasks as part of the workflow."}, {"id": "932afe12-3341-4f77-88ab-0b558e0d6ee2", "name": "Search Company Folder1", "type": "n8n-nodes-base.googleDrive", "position": [-3440, 500], "parameters": {"filter": {"whatToSearch": "folders"}, "options": {}, "resource": "fileFolder", "queryString": "={{ $('Lookup in Sheets').item.json.company }}"}, "credentials": {"googleDriveOAuth2Api": {"id": "VypmUgEf64twpmiZ", "name": "Google Drive account"}}, "typeVersion": 3, "alwaysOutputData": true, "notes": "This googleDrive node performs automated tasks as part of the workflow."}, {"id": "b9e66cf4-365a-4d11-bff9-48bf28be9e96", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "position": [-4740, 280], "parameters": {"color": 6, "width": 560, "height": 660, "content": "# 1. Trigger Settings and Filters\n\n## Configure the interval to check for new emails and apply filters to process only some emails\n\n**For example**: To create a filter that applies a label to emails **with attachments** containing the words \"invoice\" or \"receipt,\" follow these steps:\n\n1. Open your Gmail and click on the burger menu button next to the search bar to open the search options.\n2. In the `Has the words` field type in 'invoice receipt'\n3. Check the `Has attachment` checkbox\n4. Click on the \"Create filter with this search\" option at the bottom of the search window.\n5. In the filter options, select the \"Apply the label\" option and choose or create a label for these emails.\n6. Click \"Create filter\" to save your new filter.\n\n\n\n\n\n\n\n\n\n\n\n"}, "typeVersion": 1, "notes": "This stickyNote node performs automated tasks as part of the workflow."}, {"id": "2a932450-d0e9-44b4-adfb-2254b8e6e547", "name": "Sticky Note2", "type": "n8n-nodes-base.stickyNote", "position": [-3000, 220], "parameters": {"color": 6, "height": 540, "content": "# 3. Configure storage location\n## Set where to store files from the `parent folder` dropdown"}, "typeVersion": 1, "notes": "This stickyNote node performs automated tasks as part of the workflow."}, {"id": "247e4ed7-ebff-4392-adf2-4a63e80e04f4", "name": "Upload To Folder", "type": "n8n-nodes-base.googleDrive", "position": [-1100, 480], "parameters": {"name": "={{ Date.now();}}-{{ $('Loop Over Items').item.binary.data.fileName }} ", "driveId": {"__rl": true, "mode": "list", "value": "My Drive", "cachedResultUrl": "{{ $env.WEBHOOK_URL }}", "cachedResultName": "My Drive"}, "options": {"ocrLanguage": "en", "propertiesUi": {"propertyValues": [{"key": "YOUR_CREDENTIAL_HERE", "value": "={{ $('Gmail').item.json.from.value[0].address }}"}, {"key": "YOUR_CREDENTIAL_HERE", "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": "VypmUgEf64twpmiZ", "name": "Google Drive account"}}, "typeVersion": 3, "notes": "This googleDrive node performs automated tasks as part of the workflow."}, {"id": "error-acab3afe", "name": "Error Handler", "type": "n8n-nodes-base.stopAndError", "typeVersion": 1, "position": [1000, 400], "parameters": {"message": "Workflow execution error", "options": {}}}], "pinData": {}, "connections": {"13188ea7-7e66-4955-89d0-82ba4dc08dc9": {"main": [[{"node": "error-handler-13188ea7-7e66-4955-89d0-82ba4dc08dc9-c50c0d10", "type": "main", "index": 0}]]}, "ed2ababb-7022-43e1-b638-0132c08ef701": {"main": [[{"node": "error-handler-ed2ababb-7022-43e1-b638-0132c08ef701-fca35627", "type": "main", "index": 0}]]}, "086ff643-ca10-46ec-92b5-8a014fd3bf3f": {"main": [[{"node": "error-handler-086ff643-ca10-46ec-92b5-8a014fd3bf3f-100decbd", "type": "main", "index": 0}]]}, "f7009cc2-8194-40c9-98e9-edc4a29c5ce8": {"main": [[{"node": "error-handler-f7009cc2-8194-40c9-98e9-edc4a29c5ce8-8aa95113", "type": "main", "index": 0}]]}, "932afe12-3341-4f77-88ab-0b558e0d6ee2": {"main": [[{"node": "error-handler-932afe12-3341-4f77-88ab-0b558e0d6ee2-417100f2", "type": "main", "index": 0}]]}, "247e4ed7-ebff-4392-adf2-4a63e80e04f4": {"main": [[{"node": "error-handler-247e4ed7-ebff-4392-adf2-4a63e80e04f4-595f62dd", "type": "main", "index": 0}]]}}, "name": "Googledrive Workflow", "settings": {"executionOrder": "v1", "saveManualExecutions": true, "callerPolicy": "workflowsFromSameOwner", "errorWorkflow": null, "timezone": "UTC", "executionTimeout": 3600, "maxExecutions": 1000, "retryOnFail": true, "retryCount": 3, "retryDelay": 1000}, "description": "Automated workflow: Googledrive Workflow. This workflow integrates 10 different services: stickyNote, gmailTrigger, function, googleDrive, set. It contains 25 nodes and follows best practices for error handling and security.", "tags": ["automation", "n8n", "production-ready", "excellent", "optimized"], "notes": "Excellent quality workflow: Googledrive Workflow. This workflow has been optimized for production use with comprehensive error handling, security, and documentation."}