{
  "name": "Organize email attachments into Google Drive folders by company with Gmail & Sheets",
  "nodes": [
    {
      "id": "13188ea7-7e66-4955-89d0-82ba4dc08dc9",
      "name": "Search For Folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -2420,
        500
      ]
    },
    {
      "id": "ed2ababb-7022-43e1-b638-0132c08ef701",
      "name": "Create Month Folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -2060,
        680
      ]
    },
    {
      "id": "f5f2365d-0977-48b1-bd2e-29b7707839d9",
      "name": "Check If Folder Exists",
      "type": "n8n-nodes-base.if",
      "position": [
        -2240,
        500
      ]
    },
    {
      "id": "c27b0a9d-8ee2-4eae-963c-14256ffae0b8",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -4400,
        780
      ]
    },
    {
      "id": "3eac8c53-1b20-4511-9f2a-f5e838ca0fa0",
      "name": "Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1720,
        460
      ]
    },
    {
      "id": "bfae9bb5-6915-4968-8b5e-e72dd46bda55",
      "name": "Split Up Binary Data1",
      "type": "n8n-nodes-base.function",
      "position": [
        -1560,
        460
      ]
    },
    {
      "id": "baf55ab9-511f-4404-a2cc-b1c848f6f5c5",
      "name": "Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1800,
        280
      ],
      "parameters": {
        "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"
      }
    },
    {
      "id": "5d706d3a-db17-4f5f-9eac-ba91c470dbdd",
      "name": "YYYY/MM",
      "type": "n8n-nodes-base.set",
      "position": [
        -2600,
        500
      ]
    },
    {
      "id": "b20a3833-f648-454d-999b-d799727e18e8",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -1320,
        460
      ]
    },
    {
      "id": "bb8c0d21-de74-4abf-bf6c-5eef3f301513",
      "name": "Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2680,
        280
      ],
      "parameters": {
        "width": 820,
        "height": 660,
        "content": "# Checks if YYYY/MM Folder exists\n## If the directory doesn't exist it is created"
      }
    },
    {
      "id": "40971ca3-91d3-4651-8137-e973dbd2dbbd",
      "name": "Company Folder Exists",
      "type": "n8n-nodes-base.if",
      "position": [
        -3180,
        500
      ]
    },
    {
      "id": "086ff643-ca10-46ec-92b5-8a014fd3bf3f",
      "name": "Create Company Folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -2920,
        620
      ]
    },
    {
      "id": "7792afb7-61d9-402f-814b-f4625cd012bc",
      "name": "Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3500,
        120
      ],
      "parameters": {
        "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"
      }
    },
    {
      "id": "1f61ea45-49e6-4018-91ad-2144c1bbc19a",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -4120,
        280
      ],
      "parameters": {
        "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](https://docs.google.com/spreadsheets/d/1tTz9BflstxVL18YG11Ny1eiDj3FcjvtZ619b_bH"
      }
    },
    {
      "id": "f7009cc2-8194-40c9-98e9-edc4a29c5ce8",
      "name": "Lookup in Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -3900,
        780
      ]
    },
    {
      "id": "932afe12-3341-4f77-88ab-0b558e0d6ee2",
      "name": "Search Company Folder1",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -3440,
        500
      ]
    },
    {
      "id": "b9e66cf4-365a-4d11-bff9-48bf28be9e96",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -4740,
        280
      ],
      "parameters": {
        "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 *"
      }
    },
    {
      "id": "2a932450-d0e9-44b4-adfb-2254b8e6e547",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3000,
        220
      ],
      "parameters": {
        "width": null,
        "height": 540,
        "content": "# 3. Configure storage location\n## Set where to store files from the `parent folder` dropdown"
      }
    },
    {
      "id": "247e4ed7-ebff-4392-adf2-4a63e80e04f4",
      "name": "Upload To Folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -1100,
        480
      ]
    }
  ],
  "connections": {
    "Gmail": {
      "main": [
        [
          {
            "node": "Split Up Binary Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "YYYY/MM": {
      "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
          }
        ]
      ]
    },
    "Company Folder Exists": {
      "main": [
        [
          {
            "node": "YYYY/MM",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Company Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Company Folder": {
      "main": [
        [
          {
            "node": "YYYY/MM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Up Binary Data1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "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
          }
        ]
      ]
    }
  }
}