{
  "name": "Extract & classify invoices & receipts with Gmail, OpenAI and Google Drive",
  "nodes": [
    {
      "id": "c84f3a9a-66b3-4a09-b06a-9b399ea574b8",
      "name": "OpenAI",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        420,
        -240
      ]
    },
    {
      "id": "ea1fbc5b-1859-4d65-8401-30baa95fcc52",
      "name": "Configure",
      "type": "n8n-nodes-base.set",
      "position": [
        -700,
        0
      ]
    },
    {
      "id": "3ee63612-c1e7-40e6-a38f-f77f5ee3efa4",
      "name": "Iterate over email attachments",
      "type": "n8n-nodes-base.code",
      "position": [
        -200,
        0
      ]
    },
    {
      "id": "3e638471-c1c5-4bab-aa2a-12a1777225ec",
      "name": "Not a PDF",
      "type": "n8n-nodes-base.noOp",
      "position": [
        120,
        80
      ]
    },
    {
      "id": "b5af902b-2d59-49ee-b6d8-e387c59b89fd",
      "name": "Is text within token limit?",
      "type": "n8n-nodes-base.if",
      "position": [
        300,
        -100
      ]
    },
    {
      "id": "a0a8895c-ef8b-44e7-9294-1bcf629d0973",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        720,
        -120
      ]
    },
    {
      "id": "7565118a-6d44-4583-a19f-cb4177378d33",
      "name": "Is matched",
      "type": "n8n-nodes-base.if",
      "position": [
        880,
        -120
      ]
    },
    {
      "id": "074ffb7a-f83e-44b8-84fe-7b85f7245bb0",
      "name": "Upload file to folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1100,
        -140
      ]
    },
    {
      "id": "7681eb62-ba86-4c89-9b88-3ce6fc438bd4",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1080,
        0
      ]
    },
    {
      "id": "aab3d940-55c2-40d3-917a-83412d4e378d",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        -720,
        -240
      ]
    },
    {
      "id": "29a4122f-0112-4157-a50d-0a6cf83ab7fd",
      "name": "Create folder",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -920,
        0
      ]
    },
    {
      "id": "df86428f-7e63-4fd9-944c-f48af72af495",
      "name": "Aggregate attachments",
      "type": "n8n-nodes-base.code",
      "position": [
        1200,
        -340
      ]
    },
    {
      "id": "72a21bfa-6e3b-421a-a4ca-dea9e09a5b0b",
      "name": "Send email with invoices?",
      "type": "n8n-nodes-base.if",
      "position": [
        1000,
        -320
      ]
    },
    {
      "id": "bb038635-eb69-447b-a85b-e9c3caebfe3a",
      "name": "Send to my accountant",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1360,
        -280
      ]
    },
    {
      "id": "7b2e5c6c-0a95-4347-97a9-c9ffbc0e3af2",
      "name": "Get emails with attachments",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -500,
        0
      ]
    },
    {
      "id": "6d5b2c1b-657d-44bf-980d-fd428fd8d832",
      "name": "Read PDF email attachments",
      "type": "n8n-nodes-base.readPDF",
      "position": [
        120,
        -80
      ]
    },
    {
      "id": "3166f45c-306f-483a-b2c6-6768abc916a0",
      "name": "Is attachment a PDF?",
      "type": "n8n-nodes-base.if",
      "position": [
        -40,
        0
      ]
    },
    {
      "id": "866b286a-7b9b-4506-aa6b-d2049b249991",
      "name": "Optional filter for emails",
      "type": "n8n-nodes-base.filter",
      "position": [
        -360,
        0
      ]
    },
    {
      "id": "56133dba-bc93-4f65-be42-995164a45c03",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1600,
        -340
      ],
      "parameters": {
        "width": 440,
        "height": 880,
        "content": "## Gmail PDF Invoice/Receipt Classifier & Google Drive Uploader (via n8n & OpenAI)\n\n_**DISCLAIMER**: AI classification isn't perfect. Always double-check that the correct documents were identified and"
      }
    },
    {
      "id": "aa5d8126-e2ec-4476-886d-c46379f1c6e2",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -780,
        -40
      ],
      "parameters": {
        "width": 260,
        "height": 1000,
        "content": "## Parameters\n\n\n\n\n\n\n\n\n\n* **`maxTokenSize`** (Number)\n    *   **Limits PDF text length** (estimated input tokens) sent to OpenAI for classification. Prevents errors/high costs on long documents.\n    * "
      }
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Is matched",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Create folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure": {
      "main": [
        [
          {
            "node": "Get emails with attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is matched": {
      "main": [
        [
          {
            "node": "Upload file to folder",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send email with invoices?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create folder": {
      "main": [
        [
          {
            "node": "Configure",
            "type": "main",
            "index": 0
          },
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is attachment a PDF?": {
      "main": [
        [
          {
            "node": "Read PDF email attachments",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Not a PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate attachments": {
      "main": [
        [
          {
            "node": "Send to my accountant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to my accountant": {
      "main": [
        []
      ]
    },
    "Upload file to folder": {
      "main": [
        []
      ]
    },
    "Send email with invoices?": {
      "main": [
        [
          {
            "node": "Aggregate attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Optional filter for emails": {
      "main": [
        [
          {
            "node": "Iterate over email attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read PDF email attachments": {
      "main": [
        [
          {
            "node": "Is text within token limit?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get emails with attachments": {
      "main": [
        [
          {
            "node": "Optional filter for emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is text within token limit?": {
      "main": [
        [
          {
            "node": "OpenAI",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ],
        []
      ]
    },
    "Iterate over email attachments": {
      "main": [
        [
          {
            "node": "Is attachment a PDF?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}