{
  "name": "Flag duplicate and risky AP invoices with Gmail, OpenAI and Supabase",
  "nodes": [
    {
      "id": "0ae5c983-ad78-4eb6-8f0e-dfbac8737338",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        26176,
        7232
      ],
      "parameters": {
        "width": 700,
        "height": 356,
        "content": "## AP Invoice Fraud Detection\nVersion 1.0.0 — Finance\n\nProcesses incoming invoices from Gmail, extracts structured data with AI, checks Supabase for duplicate invoice numbers, validates vendor payment"
      }
    },
    {
      "id": "01b77a2c-55b4-41da-964c-e1947d447530",
      "name": "Prerequisites",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        26880,
        7248
      ],
      "parameters": {
        "width": 420,
        "height": 344,
        "content": "## Prerequisites\n- Gmail account receiving invoices (Gmail OAuth2 credential)\n- OpenAI API key (GPT-4o)\n- Supabase project with two tables:\n  - invoices: invoice_number, vendor_name, amount, status, c"
      }
    },
    {
      "id": "4688febd-754b-45f3-ba5a-8e71073b0719",
      "name": "Setup Required",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        27312,
        7248
      ],
      "parameters": {
        "width": 420,
        "height": 344,
        "content": "## Setup Required\n1. Gmail Trigger — connect Gmail OAuth2 credential\n2. Extract Invoice Data — connect OpenAI credential\n3. Check Duplicates + Check Vendor History — connect Supabase API credential, u"
      }
    },
    {
      "id": "966be176-d977-4cb1-ae2b-43a70082f232",
      "name": "How It Works",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        26192,
        7600
      ],
      "parameters": {
        "width": 500,
        "height": 520,
        "content": "## How It Works\n1. Gmail Trigger detects new invoice emails (attach PDF or include invoice details in body)\n2. AI Agent extracts: invoice number, vendor, amount, invoice date, due date, line items\n3. "
      }
    },
    {
      "id": "6327f8eb-6f67-4d01-ab54-46a95fc9110d",
      "name": "Gmail — Invoice Inbox",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        26448,
        8016
      ]
    },
    {
      "id": "7310c22e-85cd-408d-ab0c-c9bb78448ec9",
      "name": "Extract note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        26704,
        7888
      ],
      "parameters": {
        "width": 238,
        "height": 80,
        "content": "AI extracts structured invoice data from email subject, body, and attachments"
      }
    },
    {
      "id": "b25edce2-2aa5-42a0-9d37-bcc68978cba2",
      "name": "Extract Invoice Data",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        26704,
        8016
      ]
    },
    {
      "id": "d6d79de4-0bec-4773-913e-56e0729d0b9d",
      "name": "OpenAI — Extract",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        26592,
        8208
      ]
    },
    {
      "id": "ead44960-92f3-469c-96fb-37fbff3ed761",
      "name": "Invoice Data Schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        26896,
        8208
      ]
    },
    {
      "id": "d121a56a-10dc-4717-9fcd-bce791f9f6c8",
      "name": "Duplicates note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        26976,
        7888
      ],
      "parameters": {
        "width": 228,
        "height": 80,
        "content": "Queries invoices table for existing records with same invoice number"
      }
    },
    {
      "id": "6cfe2bca-abc4-487b-afa4-a703a4872c51",
      "name": "Check Duplicates",
      "type": "n8n-nodes-base.supabase",
      "position": [
        27024,
        8016
      ]
    },
    {
      "id": "29b2c5f3-d98d-4591-a0e4-0f160a7bed70",
      "name": "Count Dup note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        27232,
        7888
      ],
      "parameters": {
        "width": 255,
        "height": 96,
        "content": "Consolidates duplicate rows into a single item, counts matches"
      }
    },
    {
      "id": "28c6a089-8fa9-4f07-9fc8-ddff34d2464d",
      "name": "Count Duplicates",
      "type": "n8n-nodes-base.code",
      "position": [
        27264,
        8000
      ]
    },
    {
      "id": "6f4b34db-9590-4e01-bf44-1ae1974f24ed",
      "name": "Vendor note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        27504,
        7840
      ],
      "parameters": {
        "width": 260,
        "height": 60,
        "content": "Queries vendor history to detect unusual amounts or flagged suppliers"
      }
    },
    {
      "id": "ff913bf0-34d6-421f-a56b-154d50a1a2f4",
      "name": "Check Vendor History",
      "type": "n8n-nodes-base.supabase",
      "position": [
        27488,
        8000
      ]
    },
    {
      "id": "aea77465-e803-45f8-bdf4-342b9aeb5040",
      "name": "Merge Context note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        27776,
        7888
      ],
      "parameters": {
        "width": 238,
        "height": 80,
        "content": "Merges invoice data, duplicate count, and vendor history into one item for risk assessment"
      }
    },
    {
      "id": "574222db-ff63-48e2-b976-5671565b6084",
      "name": "Merge All Context",
      "type": "n8n-nodes-base.code",
      "position": [
        27808,
        7984
      ]
    },
    {
      "id": "df6a0c96-f5e7-4d88-921c-e7a2c1ccb8fc",
      "name": "Risk note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        28032,
        7872
      ],
      "parameters": {
        "width": 254,
        "height": 80,
        "content": "AI Agent scores fraud risk using duplicate count, vendor history, and amount deviation"
      }
    },
    {
      "id": "0732a5a9-3f99-45f8-be98-98a153e49537",
      "name": "Assess Fraud Risk",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        28000,
        7984
      ]
    },
    {
      "id": "46f49aa4-9f06-4f05-9124-dbc59982bd32",
      "name": "OpenAI — Risk",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        27776,
        8224
      ]
    },
    {
      "id": "4a9e9a7d-cde5-459d-945c-fb7715e3996d",
      "name": "Fraud Risk Schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        28240,
        8256
      ]
    },
    {
      "id": "d4f636eb-510b-4bc2-8b25-2a6686932d95",
      "name": "High Risk note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        28304,
        7856
      ],
      "parameters": {
        "width": 244,
        "height": 80,
        "content": "Routes to Slack alert path if risk requires hold, otherwise logs directly"
      }
    },
    {
      "id": "c5def029-6c26-4e86-95d1-c450028478ea",
      "name": "High Risk?",
      "type": "n8n-nodes-base.if",
      "position": [
        28336,
        7984
      ]
    },
    {
      "id": "8384f3aa-f4ff-4c7f-931c-be290d9c6e8d",
      "name": "Slack note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        28560,
        7776
      ],
      "parameters": {
        "width": 207,
        "height": 80,
        "content": "Posts fraud alert to #invoice-alerts Slack channel with full details"
      }
    },
    {
      "id": "fcae28cd-d96f-436f-849a-c37bd5fbc992",
      "name": "Alert Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        28592,
        7936
      ]
    },
    {
      "id": "eb9876b9-9d8e-4b33-970a-44f4127c5ccc",
      "name": "Send Hold Notice",
      "type": "n8n-nodes-base.gmail",
      "position": [
        28832,
        7856
      ]
    },
    {
      "id": "e71db94f-fd18-4672-a665-f46ee1ca26d5",
      "name": "Log Invoice note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        29056,
        8000
      ],
      "parameters": {
        "width": 255,
        "height": 60,
        "content": "Logs every processed invoice to Supabase for record keeping"
      }
    },
    {
      "id": "d056425b-4ac9-472c-b719-43a48f620c00",
      "name": "Log Invoice to Supabase",
      "type": "n8n-nodes-base.supabase",
      "position": [
        29120,
        8112
      ]
    }
  ],
  "connections": {
    "High Risk?": {
      "main": [
        [
          {
            "node": "Alert Slack",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Invoice to Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alert Slack": {
      "main": [
        [
          {
            "node": "Send Hold Notice",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI — Risk": {
      "ai_languageModel": [
        [
          {
            "node": "Assess Fraud Risk",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check Duplicates": {
      "main": [
        [
          {
            "node": "Count Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Count Duplicates": {
      "main": [
        [
          {
            "node": "Check Vendor History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Hold Notice": {
      "main": [
        [
          {
            "node": "Log Invoice to Supabase",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Assess Fraud Risk": {
      "main": [
        [
          {
            "node": "High Risk?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fraud Risk Schema": {
      "ai_outputParser": [
        [
          {
            "node": "Assess Fraud Risk",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Merge All Context": {
      "main": [
        [
          {
            "node": "Assess Fraud Risk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI — Extract": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Invoice Data",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Invoice Data Schema": {
      "ai_outputParser": [
        [
          {
            "node": "Extract Invoice Data",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Check Vendor History": {
      "main": [
        [
          {
            "node": "Merge All Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Invoice Data": {
      "main": [
        [
          {
            "node": "Check Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail — Invoice Inbox": {
      "main": [
        [
          {
            "node": "Extract Invoice Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}