Automated Discount Voucher System for E-commerce Customers - n8n Workflow

Use this powerful n8n workflow to automatically analyze customer order data (e.g., Magento 2), identify high-value shoppers, generate unique discount codes, and send vouchers via the Gmail n8n node. Explore official n8n templates for CRM automation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Markdown-formatted text:

E-commerce Managers running platforms like Magento 2 who need automated CRM retention strategies.
Marketing teams looking for robust n8n templates to automate personalized customer outreach.
System administrators seeking a reliable n8n workflow to schedule complex API interactions and email delivery.
Users familiar with connecting HTTP Request n8n nodes to external e-commerce APIs.

Overview

Manually identifying high-value customers, creating segmented sales rules, generating unique coupon codes, and sending personalized emails is a time-consuming and error-prone process. This automated n8n workflow solves this by running a complete retention campaign on a schedule.

This robust n8n workflow starts with a Cron n8n trigger, calculating relevant date ranges and fetching necessary media paths (like a company logo). It then queries your e-commerce platform (via HTTP Request n8n node) to retrieve orders and calculates the total spent by customers over the last three months. By using core logic flow control, the n8n workflow filters for customers exceeding a specific spend threshold. For those high-value customers, the automation dynamically creates a sales rule and generates a unique coupon code before sending a personalized email using the Gmail n8n node. This approach ensures maximum efficiency and accuracy in rewarding loyalty.

How it Works

Markdown-formatted text:


  1. Scheduled Start: The Cron n8n trigger initiates the entire process regularly (e.g., daily or weekly).

  2. Date and Asset Preparation: The n8n workflow first fetches any necessary assets (Get Media Path) and prepares them (SetOrGet Logo). A specialized Code n8n node (Get 3 Month Dates) calculates the exact date range required for filtering recent orders.

  3. Data Retrieval: The Get Completed Orders HTTP Request n8n node uses the calculated dates to query the e-commerce API (like Magento 2) for recent transactions.

  4. Value Calculation: The Get Customer Order Value Code n8n node processes the retrieved orders, aggregating the total sales value for each unique customer ID.

  5. Decision Point: The central If n8n node checks if a customer's total order value meets the defined threshold for being considered "high-value."

  6. Success Path (High Value): If the condition is true, the n8n workflow proceeds to two critical HTTP Request steps: Create New Sales Rule and Generate Coupon for Each Customer. These steps interact with the e-commerce API to set up the discount parameters and create the unique voucher code.

  7. Voucher Delivery: The final Send Voucher Gmail n8n node sends a customized, personalized email containing the unique coupon code directly to the customer.

  8. Reporting Path (Alternative): If the condition is false (or for logging purposes), the Send Report Gmail n8n node can be used to notify the administrative team about the execution status or customers who did not qualify.

Installation Guide

Markdown-formatted text:


  1. Import the n8n Workflow: Copy the provided JSON data and import it directly into your n8n instance using the 'New' -> 'Import from JSON' function.

  2. Configure Credentials:

HTTP Request Nodes: You will need credentials (API keys, tokens) for your e-commerce platform (e.g., Magento 2 Admin Integration token) to configure the HTTP Request n8n node credentials. These are essential for fetching orders and creating sales rules.
Gmail Nodes: Set up your Gmail OAuth 2.0 or API key credentials for the Send Voucher and Send Report Gmail n8n node instances.

  1. Customize Node Parameters:

Review the Get Customer Order Value Code n8n node and the If n8n node to ensure the high-value spending threshold aligns with your business rules.
Verify the API endpoints and JSON payloads within the HTTP Request n8n node configuration to match your specific e-commerce setup (URL, headers, and body content).

  1. Activate: Once credentials and configurations are set, activate the Cron n8n trigger to start the scheduled automation.

Node Details

Markdown-formatted text:

Cron (n8n trigger):
Function: Serves as the primary n8n trigger, initiating the entire n8n workflow on a predefined schedule (e.g., daily).
Key Configuration: Schedule frequency.
Get 3 Month Dates (Code n8n node):
Function: Custom scripting to dynamically calculate the date range (e.g., last 90 days) needed for filtering recent customer orders.
Get Completed Orders (HTTP Request n8n node):
Function: Queries the e-commerce API to retrieve a list of completed orders within the calculated date range, filtering for relevant customer data.
Get Customer Order Value (Code n8n node):
Function: Processes the order data from the previous n8n node, calculating the cumulative lifetime or recent order value for each customer.
If (n8n node - Core Logic Flow Control):
Function: Directs the n8n workflow flow based on whether the calculated customer order value meets the high-value threshold.
Create New Sales Rule (HTTP Request n8n node):
Function: Only executed for high-value customers. Calls the e-commerce API to create the base sales rule (e.g., 15% off). Set to continue on error, indicating resilience is built into this specific n8n workflow step.
Generate Coupon for Each Customer (HTTP Request n8n node):
Function: Generates a unique, single-use coupon code associated with the newly created sales rule for the individual customer.
Send Voucher (Gmail n8n node):
* Function: Delivers the personalized email containing the unique discount code and branding assets (referenced from earlier steps) to the high-value customer.

Related n8n Workflows

Paid

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by
Kanaka Kishore Kandregula
Kanaka Kishore Kandregula

Experienced Magento 2 Developer with 10+ years of expertise in building and optimizing eCommerce solutions. Over the past year, I’ve expanded my skills into workflow automation using n8n, streamlining business processes and integrating systems for efficiency. Passionate about solving complex problems, enhancing performance, and leveraging automation to drive smarter workflows.

Featured*