{
  "name": "Automatic email invoice archiving & data extraction with Gmail, Drive & AI",
  "nodes": [
    {
      "id": "8740476c-9d06-414b-b68a-828df048b29e",
      "name": "AI_Agent-fields",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2736,
        672
      ]
    },
    {
      "id": "f6d0666f-ba52-4ce9-a8bb-b6ea735427ca",
      "name": "Code_extractFields",
      "type": "n8n-nodes-base.code",
      "position": [
        3024,
        672
      ]
    },
    {
      "id": "e308190d-ab88-430c-ac06-5835edbf0d7f",
      "name": "GoogleSheets_save",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3216,
        672
      ]
    },
    {
      "id": "3c478faf-ec04-4da4-a7d4-34a208689ab0",
      "name": "downloadFile",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2352,
        208
      ]
    },
    {
      "id": "cb8e5ab0-cb78-4c18-88cc-6301ce5a00db",
      "name": "GoogleDrive-upload-file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2144,
        208
      ]
    },
    {
      "id": "4966a033-d088-4ef1-88d8-b338b3a912b2",
      "name": "Gmail-Get_Invoice",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1936,
        208
      ]
    },
    {
      "id": "b45ff76f-eab8-4989-9c0f-3e965b6b2aee",
      "name": "Delete a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        3168,
        208
      ]
    },
    {
      "id": "7f91a088-b772-4cf0-9460-3d8b1f907286",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        672,
        192
      ]
    },
    {
      "id": "06bbcd36-63f8-4675-8844-50d0f028efa2",
      "name": "Get many messages",
      "type": "n8n-nodes-base.gmail",
      "position": [
        928,
        192
      ]
    },
    {
      "id": "b8777576-41e7-46c0-86b8-7af73f30ab5c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        -48
      ],
      "parameters": {
        "width": 752,
        "height": 720,
        "content": "## Automated Invoice Archiving - overview\n\nThis workflow automatically collects invoice emails from your ISP/utility provider, saves attached PDFs to Google Drive (and optionally SFTP), extracts key i"
      }
    },
    {
      "id": "22841f63-b10a-48bd-bf8e-fbd51a65beac",
      "name": "Extract from File1",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2560,
        416
      ]
    },
    {
      "id": "f34ed231-eb4e-4c6d-afe4-55002ec51d8f",
      "name": "OpenRouter Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        2736,
        816
      ]
    },
    {
      "id": "f544762a-4d82-4638-99f5-dd16cf233bc0",
      "name": "Delete a file1",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2944,
        208
      ]
    },
    {
      "id": "95b99314-b4c1-4b3b-af12-ac5ee64cff06",
      "name": "Filter-contains_attachment",
      "type": "n8n-nodes-base.filter",
      "position": [
        1168,
        192
      ]
    },
    {
      "id": "5a407aa3-d3d1-4f45-9c4a-88a5dd0cfdb7",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        -48
      ],
      "parameters": {
        "width": null,
        "height": 400,
        "content": "### SECTION 1 Trigger\n\nRuns the workflow on a schedule you choose. Adjust interval as needed (hourly, daily, etc.)."
      }
    },
    {
      "id": "163f9fb4-9dc1-4e92-83ee-ecc3e1510585",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        896,
        -48
      ],
      "parameters": {
        "width": 560,
        "height": 400,
        "content": "### SECTION 2.1 — Email Intake & Attachment filtering\n\nFetches messages from a specific sender and filters only emails containing PDF attachments.\n\n**Setup:**\nIn **Gmail → Get Many Messages**, enter t"
      }
    },
    {
      "id": "31b2113c-b7f7-45f2-b277-1b3800c8c68d",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2096,
        -48
      ],
      "parameters": {
        "width": 816,
        "height": 416,
        "content": "### SECTION 3 — Download & Storage\n\nDownloads the invoice PDF and saves it to Google Drive. You can optionally upload a copy to your FTP/SFTP server.\n\n**Google Drive:**\nConnect your Drive account: [🔗 "
      }
    },
    {
      "id": "c633ca42-aeb2-42d9-9a53-6f64ed13a5ad",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1792,
        400
      ],
      "parameters": {
        "width": 896,
        "height": null,
        "content": "### SECTION 4 — PDF Text Extraction\n\nConverts the PDF into text before sending it to the AI model. OCR not required unless the PDF is image-only."
      }
    },
    {
      "id": "08b97c66-9033-4b59-aa9f-2be21f09fee6",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2704,
        400
      ],
      "parameters": {
        "width": 448,
        "height": 544,
        "content": "### SECTION 5 — AI Parsing\n\nThe AI Agent extracts structured data (date, vendor, amount, items). The Code node cleans the JSON.\n\n**Setup**\n Enter your LLM provider API key (OpenRouter/OpenAI).\n Ensure"
      }
    },
    {
      "id": "34bfa6d9-f7ea-4acb-95f6-1c57bc6a89d2",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3168,
        400
      ],
      "parameters": {
        "width": 352,
        "height": 544,
        "content": "### SECTION 6 - GoogleSheets Logging\n\n**Setup**\nConnect your Google Sheets Service Account.\nSet **Document ID** and **Sheet Name**.\nCreate these columns in the first row:\n\n* **Vendor**\n* **Type**\n* **"
      }
    },
    {
      "id": "b464e077-d9e3-4100-b6f5-71c5c3117f9a",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        2560,
        208
      ]
    },
    {
      "id": "7f948036-e8a3-4c33-a934-c0e6dcdc5bc6",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1680,
        192
      ]
    },
    {
      "id": "c993184f-56b6-4c05-9868-963917d2dea7",
      "name": "Check: Message already processed",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1520,
        192
      ]
    },
    {
      "id": "9f7b972a-3ee1-4ba0-bb35-145aef6efbef",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1472,
        -48
      ],
      "parameters": {
        "width": 416,
        "height": 416,
        "content": "### Section 3: Check if already existing\n\nPrevents duplicate processing of the same email.\nThis section checks whether the current Gmail message has already been processed by looking up its Gmail mess"
      }
    },
    {
      "id": "08bbcd5d-dc15-48bd-9d29-a6bb8316364b",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1904,
        -48
      ],
      "parameters": {
        "width": 176,
        "height": 416,
        "content": "### Section 2.2\n\nGet attachment from Gmail \n(binary file)"
      }
    },
    {
      "id": "114f1c8c-c5de-4f09-ab00-53acff498026",
      "name": "FTP-upload",
      "type": "n8n-nodes-base.ftp",
      "position": [
        2752,
        208
      ]
    }
  ],
  "connections": {
    "FTP-upload": {
      "main": [
        [
          {
            "node": "Delete a file1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "downloadFile": {
      "main": [
        [
          {
            "node": "Extract from File1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete a file1": {
      "main": [
        [
          {
            "node": "Delete a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI_Agent-fields": {
      "main": [
        [
          {
            "node": "Code_extractFields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get many messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get many messages": {
      "main": [
        [
          {
            "node": "Filter-contains_attachment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail-Get_Invoice": {
      "main": [
        [
          {
            "node": "GoogleDrive-upload-file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "FTP-upload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code_extractFields": {
      "main": [
        [
          {
            "node": "GoogleSheets_save",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File1": {
      "main": [
        [
          {
            "node": "AI_Agent-fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI_Agent-fields",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "GoogleDrive-upload-file": {
      "main": [
        [
          {
            "node": "downloadFile",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter-contains_attachment": {
      "main": [
        [
          {
            "node": "Check: Message already processed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}