Process Sales CSVs into Invoices with Data Tables and Email Notifications

๐Ÿงพ Smart Sales Invoice Processor (Data tables Edition)

Transform uploaded sales CSV files into validated, enriched invoices, all handled natively inside n8n using Data tables, validation logic, enrichment, duplicate detection, and automated email notifications.

This workflow demonstrates a full ETL + business automation pattern, turning raw CSV data into structured, auditable records ready for storage and customer notifications.

โœจ Features โœ… Multi-format CSV input (file upload or raw text)
โœ… Validation for email, quantity, date, and required fields
โœ… Automatic error handling with 400 Bad Request JSON response for invalid CSVs
โœ… Product enrichment from Products Datatable
โœ… Invoice creation and storage in Invoices Datatable
โœ… Automated subtotal, tax, and total calculation
โœ… Duplicate order detection with 409 Conflict response
โœ… Ready-to-send email confirmations (simulated in this version)
โœ… Fully native, no external integrations required

๐Ÿงฉ Use Cases E-commerce order and invoice automation
Internal accounting or ERP data ingestion
Migrating CSV-based legacy systems into n8n
Automated business logic for B2B integrations

โš™๏ธ Setup Instructions

1๏ธโƒฃ Create two n8n Data tables

Products Stores your product catalog with SKU-based pricing and tax details.

| Column | Type | Example | | -------- | ------ | -------------- | | sku | String | PROD-001 | | name | String | Premium Widget | | price | Number | 49.99 | | tax_rate | Number | 0.10 |

Invoices Stores validated, calculated invoices created by this workflow.

| Column | Type | Example | | -------------- | -------- | ------------------------------------------- | | invoice_id | String | INV-20251103-001 | | customer_email | String | john@example.com | | order_date | Date | 2025-01-15 | | subtotal | Number | 99.98 | | total_tax | Number | 10.00 | | grand_total | Number | 109.98 | | created_at | DateTime | 2025-11-03T08:00:00Z |

2๏ธโƒฃ Import Workflow Import the provided workflow JSON file into your n8n instance.

3๏ธโƒฃ Test the Workflow Use cURL or Postman to send a test CSV to your endpoint.

curl -X POST
-H "Content-Type: text/csv"
--data-binary $'sku,quantity,customer_email,order_date\nPROD-001,2,john@example.com,2025-01-15\nPROD-002,1,jane@example.com,2025-01-15'
https://<your-n8n-url>/webhook/process-sales

๐Ÿ“ฆ Example Responses โœ… Success (HTTP 200)

{ "success": true, "processed_at": "2025-11-04T15:36:52.899Z", "invoice_count": 1, "invoices": { "to": "john@example.com", "subject": "Invoice INV-1762270612772-1 - Order Confirmation", "body": "Dear Customer,\n\nThank you for your order!\n\nInvoice ID: INV-1762270612772-1\nOrder Date: 1/14/2025\n\nSubtotal: $99.98\nTax: $10.00\nGrand Total: $109.98\n\nThank you for your business!\n\nBest regards,\nSales Team" }, "email_notifications": [ { "to": "jane@example.com", "subject": "Invoice INV-1762270612772-2 - Order Confirmation", "body": "Dear Customer,\n\nThank you for your order!\n\nInvoice ID: INV-1762270612772-2\nOrder Date: 1/14/2025\n\nSubtotal: $89.99\nTax: $9.00\nGrand Total: $98.99\n\nThank you for your business!\n\nBest regards,\nSales Team" } ], "message": "All invoices processed and customers notified" }

โŒ Validation Error (HTTP 400)

Occurs when the CSV file is missing required columns or contains invalid data. { "success": false, "message": "CSV validation failed", "error": "Validation failed: [ { "row": 2, "errors": ["Valid email is required"] } ]" }

๐Ÿง  How It Works

Webhook receives uploaded CSV or raw text
Code node parses and validates data
Data table node loads product info (price, tax rate)
Calculation node generates invoice totals per customer
Duplicate check prevents reprocessing
Data table insert saves invoices
Email preparation creates personalized confirmations
Webhook response returns structured JSON (200 / 400 / 409)

๐Ÿ” Requirements

n8n version โ‰ฅ 1.41.0
Data tables** feature enabled
Publicly accessible webhook URL (for testing)
(Optional) Connect a real email node (Gmail or SMTP) to send messages

๐Ÿ Result Highlights

Full CSV โ†’ Validation โ†’ Data tables โ†’ Email โ†’ JSON Response pipeline
Includes built-in structured error handling (400 / 409)
100% native n8n functionality**
Perfect example of Data tables + logic-based automation for business use cases

0
Downloads
0
Views
7.52
Quality Score
beginner
Complexity
Author:Patrick Siewert(View Original โ†’)
Created:11/9/2025
Updated:11/21/2025

๐Ÿ”’ Please log in to import templates to n8n and favorite templates

Workflow Visualization

Loading...

Preparing workflow renderer

Comments (0)

Login to post comments