{
  "name": "Process sales CSVs into invoices with data tables and email notifications",
  "nodes": [
    {
      "id": "c53cbd78-7962-40b5-a5c6-5e8bf7605d68",
      "name": "Documentation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        896,
        -1088
      ],
      "parameters": {
        "width": 680,
        "height": 1016,
        "content": "## 🧾 Smart Sales Invoice Processor (Data tables Edition)\n\nTransform uploaded sales CSV files into validated, enriched invoices — stored natively in **n8n Data tables** with automatic calculations, dup"
      }
    },
    {
      "id": "a05c65e8-d535-4db0-b93a-1b0e48f1c8df",
      "name": "Receive Sales CSV",
      "type": "n8n-nodes-base.webhook",
      "position": [
        944,
        208
      ]
    },
    {
      "id": "66920233-1f19-44a2-912b-3a91d927c43a",
      "name": "Check Upload Type",
      "type": "n8n-nodes-base.if",
      "position": [
        1168,
        208
      ]
    },
    {
      "id": "dd70bd76-3c1c-4e86-937c-be5412fb153c",
      "name": "Extract CSV Text",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        1392,
        304
      ]
    },
    {
      "id": "67ce54b9-cdc0-4a0a-8042-3b0d706ee6d1",
      "name": "Parse & Validate CSV",
      "type": "n8n-nodes-base.code",
      "position": [
        1616,
        208
      ]
    },
    {
      "id": "5b8569d9-1bf2-45da-825b-6b4a83495381",
      "name": "Enrich with Product Data",
      "type": "n8n-nodes-base.code",
      "position": [
        2064,
        208
      ]
    },
    {
      "id": "52a5ad1f-acb9-4024-a468-eb308e0cfe35",
      "name": "Calculate Invoice Totals",
      "type": "n8n-nodes-base.code",
      "position": [
        2288,
        208
      ]
    },
    {
      "id": "29349274-23bc-4824-9b7d-24feeecc2d97",
      "name": "Check for Duplicates",
      "type": "n8n-nodes-base.code",
      "position": [
        2512,
        208
      ]
    },
    {
      "id": "3c77bba1-c7b9-4be0-a3c1-8c8ec78694b3",
      "name": "Has Valid Invoices?",
      "type": "n8n-nodes-base.if",
      "position": [
        2736,
        208
      ]
    },
    {
      "id": "6b1a5618-7915-4313-8024-0698983938d5",
      "name": "Prepare Email Notifications",
      "type": "n8n-nodes-base.code",
      "position": [
        3408,
        112
      ]
    },
    {
      "id": "026040a1-9dcc-455f-a964-3197f72856fe",
      "name": "Email Info",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3536,
        -48
      ],
      "parameters": {
        "width": 280,
        "height": 352,
        "content": "## 📧 Email Node\n\nIn production, connect:\n- Gmail\n\nFor now, emails are simulated."
      }
    },
    {
      "id": "f1a76f11-0b4f-446c-bada-17d1b261057e",
      "name": "Merge Results",
      "type": "n8n-nodes-base.code",
      "position": [
        3856,
        112
      ]
    },
    {
      "id": "81e161e3-9ab2-472a-a36c-7d315cc729ee",
      "name": "Return Success Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        4080,
        112
      ]
    },
    {
      "id": "2e7de734-053c-48ae-94b8-1bf19bdb09ac",
      "name": "Return Duplicate Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        2960,
        304
      ]
    },
    {
      "id": "b128cc46-f310-4d59-8986-980798871bcd",
      "name": "Load Product Catalog",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1840,
        208
      ]
    },
    {
      "id": "7d70deb1-2874-48b4-b9bc-77d1f11efa54",
      "name": "Insert row",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        2960,
        112
      ]
    },
    {
      "id": "5863af7a-9e7b-4bd9-a27a-1695c0a03a75",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        3184,
        112
      ]
    },
    {
      "id": "7a1f9da9-98de-46cf-a7b0-3ee88c63f1ff",
      "name": "Email Output Preview",
      "type": "n8n-nodes-base.set",
      "position": [
        3632,
        112
      ]
    },
    {
      "id": "764e6fd1-4872-4af9-90c4-d869d0bfc121",
      "name": "Extract from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        1392,
        112
      ]
    },
    {
      "id": "584e8427-28c2-4793-a022-a054fbcc006d",
      "name": "Return Validation Error",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1840,
        416
      ]
    },
    {
      "id": "1f47fe85-e27a-48ec-a06c-70f2aeb2e1e7",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1600,
        -1104
      ],
      "parameters": {
        "width": 2192,
        "height": 1024,
        "content": "### 🧪 Test with cURL\n\n#### ✅ Valid Example\n```bash\ncurl -X POST \\\n  -H \"Content-Type: text/csv\" \\\n  --data-binary $'sku,quantity,customer_email,order_date\\nPROD-001,2,john@example.com,2025-01-15\\nPROD"
      }
    }
  ],
  "connections": {
    "Aggregate": {
      "main": [
        [
          {
            "node": "Prepare Email Notifications",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert row": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Results": {
      "main": [
        [
          {
            "node": "Return Success Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract CSV Text": {
      "main": [
        [
          {
            "node": "Parse & Validate CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Upload Type": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract CSV Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Parse & Validate CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Sales CSV": {
      "main": [
        [
          {
            "node": "Check Upload Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Valid Invoices?": {
      "main": [
        [
          {
            "node": "Insert row",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Return Duplicate Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for Duplicates": {
      "main": [
        [
          {
            "node": "Has Valid Invoices?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Output Preview": {
      "main": [
        [
          {
            "node": "Merge Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load Product Catalog": {
      "main": [
        [
          {
            "node": "Enrich with Product Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse & Validate CSV": {
      "main": [
        [
          {
            "node": "Load Product Catalog",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Return Validation Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Invoice Totals": {
      "main": [
        [
          {
            "node": "Check for Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enrich with Product Data": {
      "main": [
        [
          {
            "node": "Calculate Invoice Totals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Email Notifications": {
      "main": [
        [
          {
            "node": "Email Output Preview",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}