{
  "name": "Extract & organize email invoices with Gmail, Drive & OpenAI GPT",
  "nodes": [
    {
      "id": "6d9797e9-c99f-4efa-985a-c43cd4f8b6cc",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1632,
        512
      ]
    },
    {
      "id": "27af62f4-2621-4ef6-a632-6055b6cae33b",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1792,
        560
      ]
    },
    {
      "id": "7a128186-cb72-41ce-9763-cdd888e029bf",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2240,
        576
      ]
    },
    {
      "id": "ecfb06b1-c5f2-4803-99c4-007cc72938d8",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2224,
        416
      ]
    },
    {
      "id": "8a51021e-e72a-4bfb-9289-14779c1ba073",
      "name": "Structured Output Parser1",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        2464,
        528
      ]
    },
    {
      "id": "a16933f8-7506-4549-95c8-efbea1550bdf",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        784,
        336
      ]
    },
    {
      "id": "5b76b6d8-5a0a-4ee0-a2c1-73369af3b3a2",
      "name": "Upload file",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        3264,
        160
      ]
    },
    {
      "id": "4e713889-d996-4436-a5a9-879d580ef64e",
      "name": "Invoice Recognition Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1648,
        288
      ]
    },
    {
      "id": "d2160eac-2baa-4121-9e42-8422a7c6d0e2",
      "name": "Invoice Data extractor",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2224,
        192
      ]
    },
    {
      "id": "cf993c5d-b98c-45ef-ad61-45ca641a39dc",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        1376,
        336
      ]
    },
    {
      "id": "5684ec8f-fdd4-48dc-8572-368aa5f58f26",
      "name": "Check wether it is an invoice",
      "type": "n8n-nodes-base.if",
      "position": [
        1984,
        384
      ]
    },
    {
      "id": "7c8cae1c-643f-4284-a5c8-f98b3df1624e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        768,
        32
      ],
      "parameters": {
        "width": 496,
        "height": 688,
        "content": "## Gmail Trigger based on user customized interval\n**then get the gmail parameter inclusive text and attachments and extract all pdf files from attachments with js-code"
      }
    },
    {
      "id": "fc0c1a5c-dfae-4807-8f84-668c716c3c9f",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1280,
        32
      ],
      "parameters": {
        "width": 288,
        "height": 688,
        "content": "## Extract the text from the pdf attachment if exists\n**otherwise ignore and further process"
      }
    },
    {
      "id": "8a5f7033-49ce-4e64-9296-1f3cb3711b69",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1600,
        32
      ],
      "parameters": {
        "width": 560,
        "height": 688,
        "content": "## Analyse the context of the mail and the attachments and process further in case it is an invoice\n**otherwise ignore and stop the process"
      }
    },
    {
      "id": "315a69ed-fe06-4630-984e-042b724599a3",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2160,
        32
      ],
      "parameters": {
        "width": 336,
        "height": 688,
        "content": "## Extract the relevant invoice parameters\n**date_email, date_invoice, invoice_nr, description, provider, net_amount, vat, gross_amount, label, currency\n"
      }
    },
    {
      "id": "1a0e84bb-ef25-41f4-9e53-f743761991dd",
      "name": "Check wether it was a file-invoice or text invoice",
      "type": "n8n-nodes-base.if",
      "position": [
        2560,
        320
      ]
    },
    {
      "id": "ac9ec995-a6fb-459a-ba7c-7cd93ca607ef",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2496,
        32
      ],
      "parameters": {
        "width": 208,
        "height": 688,
        "content": "## Was the invoice in attachments or in the mail body?\n\n"
      }
    },
    {
      "id": "0e389153-4102-466a-8851-7f694292909b",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2704,
        32
      ],
      "parameters": {
        "width": 976,
        "height": 336,
        "content": "## Document the paramters in sheet, uoload the invoice file to drive and update the sheet with the invoice-url in your drive, and finally mark the invoice message as read in you gmail\n\n"
      }
    },
    {
      "id": "fc7ab85c-d7b8-4452-9e4f-60f53a0ef0fb",
      "name": "Document the invoice parameters",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2800,
        144
      ]
    },
    {
      "id": "39eb6c11-d75c-4967-97cc-3f6078fa2cee",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2704,
        384
      ],
      "parameters": {
        "width": 976,
        "height": 336,
        "content": "## Document the paramters in sheet, generate a link to the email\n\n"
      }
    },
    {
      "id": "a2305d63-67c3-4743-a2e0-ed738a6f5b1a",
      "name": "Update Invoice parameters",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3472,
        160
      ]
    },
    {
      "id": "3f3616f4-f2e5-415d-9cf6-b2944780cefe",
      "name": "Update text Invoice parameters",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3104,
        528
      ]
    },
    {
      "id": "195ac57c-2dad-415a-a432-6a7c7dc8edaf",
      "name": "Mark a message as read",
      "type": "n8n-nodes-base.gmail",
      "position": [
        3808,
        320
      ]
    },
    {
      "id": "b8f65fe4-0be2-4e40-84c3-7b3cc4988236",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        1136,
        336
      ]
    },
    {
      "id": "e0923dcc-5e65-4b5c-982a-1f5054eba3a9",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        3056,
        160
      ]
    },
    {
      "id": "c7b9e396-e66a-43df-8fe3-eb867b5084c5",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        -176
      ],
      "parameters": {
        "width": 784,
        "height": 1360,
        "content": "## Who’s it for\n\nThis template is for founders, finance teams, and solo operators who receive lots of invoices by email and want them captured automatically in a single, searchable source of truth. If"
      }
    },
    {
      "id": "615cac4d-1a01-4a0e-ad83-0d2699cb904b",
      "name": "Get a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        944,
        336
      ]
    },
    {
      "id": "ca5f4e6a-320e-4ff5-b289-226f02a4b1f2",
      "name": "OpenAI Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2528,
        752
      ]
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Upload file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload file": {
      "main": [
        [
          {
            "node": "Update Invoice parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a message": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Get a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Invoice Recognition Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Invoice Recognition Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Invoice Data extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Structured Output Parser1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Invoice Data extractor": {
      "main": [
        [
          {
            "node": "Check wether it was a file-invoice or text invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Invoice Recognition Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Invoice Recognition Agent": {
      "main": [
        [
          {
            "node": "Check wether it is an invoice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser1": {
      "ai_outputParser": [
        [
          {
            "node": "Invoice Data extractor",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Update Invoice parameters": {
      "main": [
        [
          {
            "node": "Mark a message as read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check wether it is an invoice": {
      "main": [
        [
          {
            "node": "Invoice Data extractor",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update text Invoice parameters": {
      "main": [
        [
          {
            "node": "Mark a message as read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Document the invoice parameters": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check wether it was a file-invoice or text invoice": {
      "main": [
        [
          {
            "node": "Document the invoice parameters",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update text Invoice parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}