πŸ”¬ Parse & track orders from email with Gemini/GPT & Notion database sync

⚑ 139 views Β· πŸ”¬ Document Extraction & Analysis

Description

Automated Email Order Tracking System with AI Classification and Notion Sync

Overview

⚠️ Self-Hosted Solution Required
This workflow requires a self-hosted n8n instance with active integrations for Gmail, Google Gemini AI, OpenAI, and Notion. API credentials and database IDs must be configured before use.


Template Image

image.png

Description

This intelligent automation system monitors your Gmail inbox for order-related emails, extracts key order information using AI, and automatically syncs the data to a Notion database for centralized order tracking. Perfect for individuals managing multiple e-commerce accounts or small businesses tracking customer orders across various platforms (Amazon, Noon, Namshi, etc.).

What This Workflow Does

  1. Email Monitoring: Continuously monitors Gmail inbox for new incoming emails
  2. Smart Classification: Uses AI to identify order-related emails (confirmations, shipping notifications, delivery updates)
  3. Intelligent Extraction: Parses email content to extract order details (order number, items, prices, status, delivery info)
  4. Database Synchronization: Automatically creates or updates Notion database records with order information
  5. Status Tracking: Monitors order progression through stages (Ordered β†’ Shipped β†’ Out for Delivery β†’ Delivered)

Key Features

Technologies Used


Prerequisites

Before setting up this workflow, ensure you have:

  1. Self-hosted n8n instance (version 1.0.0 or higher)
  2. Gmail account with IMAP access enabled
  3. Google Gemini API key OR OpenAI API key
  4. Notion workspace with:
    • Integration access configured
    • Database created with the required schema (see below)
    • Integration token/API key

Notion Database Schema

Create a Notion database with the following properties:

Required Properties

Property NameTypeDescription
Name of the ItemTitleProduct/item name
Order NumberTextUnique order identifier
QuantityNumberNumber of items
Expected DateDate or TextExpected delivery date
Order StatusSelectOptions: Ordered, Shipped, Out for Delivery, Delivered
Property NameTypeDescription
VendorSelectE-commerce platform (Amazon, Noon, etc.)
Customer NameRich TextOrder recipient name
PriceNumber or Rich TextItem price
Order TotalNumberTotal order amount
CurrencySelectCurrency code (AED, USD, SAR, etc.)
Delivery LocationRich TextDelivery city/address
NotesRich TextStatus change history
Created DateCreated TimeAuto-populated by Notion
Last UpdatedLast Edited TimeAuto-populated by Notion

Setup Instructions

Step 1: Import the Workflow

  1. Copy the workflow JSON from this template
  2. In your n8n instance, go to Workflows β†’ Add Workflow β†’ Import from File/URL
  3. Paste the JSON and click Import

Step 2: Configure Gmail Trigger

  1. Click on the Gmail Trigger node
  2. Click Create New Credential
  3. Follow the OAuth authentication flow to connect your Gmail account
  4. Configure trigger settings:
    • Trigger On: Message Received
    • Filters: (Optional) Add label filters to monitor specific folders

Step 3: Configure AI Model (Choose One)

Option A: Google Gemini AI

  1. Click on the Google Gemini AI Model node
  2. Click Create New Credential
  3. Enter your Gemini API key (obtain from Google AI Studio)
  4. Select model: gemini-1.5-pro or gemini-1.5-flash

Option B: OpenAI

  1. Click on the OpenAI Chat Model node
  2. Click Create New Credential
  3. Enter your OpenAI API key (obtain from OpenAI Platform)
  4. Select model: gpt-4o or gpt-4-turbo

Step 4: Update Email Classification Node

  1. Click on the Check Email Type node (JavaScript code)
  2. Review the classification patterns (pre-configured for common e-commerce emails)
  3. (Optional) Add custom keywords specific to your vendors

Step 5: Configure Notion Integration

5.1: Create Notion Integration

  1. Go to Notion Integrations
  2. Click New Integration
  3. Name it (e.g., β€œn8n Order Tracker”)
  4. Select your workspace
  5. Copy the Internal Integration Token

5.2: Share Database with Integration

  1. Open your Notion order database
  2. Click Share β†’ Invite
  3. Search for your integration name and select it
  4. Grant Edit permissions

5.3: Get Database ID

  1. Open your Notion database in browser
  2. Copy the database ID from the URL:
    https://notion.so/workspace/DATABASE_ID?v=...
                               ^^^^^^^^^^^^

5.4: Configure Notion Nodes

  1. Click on Search a database in Notion node

  2. Click Create New Credential

  3. Paste your Integration Token

  4. In the node parameters:

    • Database ID: Paste your database ID
    • Filter: Set to search by Order Number property
  5. Repeat credential setup for Create a database page in Notion and Update a database page in Notion nodes


Step 6: Update Agent Prompts

  1. Click on the Email Classification and Extraction Agent node

  2. Review the system prompt (pre-configured for common order emails)

  3. Update the {{$now}} variable if using a different timezone

  4. (Optional) Customize extraction rules for specific vendors

  5. Click on the Order Database Sync Agent node

  6. Replace {{notion_database_id}} with your actual database ID in the prompt

  7. Review status handling logic


Step 7: Test the Workflow

  1. Click Execute Workflow to activate it
  2. Send yourself a test order confirmation email
  3. Monitor the execution:
    • Check if email was classified correctly
    • Verify extraction output in the AI agent node
    • Confirm Notion database was updated
  4. Review your Notion database for the new/updated record

Step 8: Activate for Production

  1. Click Active toggle in the top-right corner
  2. The workflow will now run automatically for new emails
  3. Monitor executions in the Executions tab

Workflow Node Descriptions

Email Trigger

Monitors Gmail inbox for new incoming emails and triggers the workflow when a message is received.

Check Email Type

JavaScript code node that analyzes email content using pattern matching to identify order-related emails based on keywords, order numbers, and shipping terminology.

Email Router (IF Node)

Routes emails based on classification results:

Email Classification and Extraction Agent

AI-powered parser using Google Gemini or OpenAI to extract structured order information:

Structured Output Parser

Validates and formats AI extraction output into clean JSON for downstream processing.

Search a database in Notion

Queries the Notion database by order number to check if a record already exists, preventing duplicates.

Order Database Sync Agent

Intelligent database manager that decides whether to create new records or update existing ones based on search results and status comparison.

Create a database page in Notion

Adds new order records to Notion when no existing record is found.

Update a database page in Notion

Modifies existing records when order status changes, appending timestamped notes for audit history.

No Action Taken

Terminates workflow branch for non-order emails with no further processing.


Customization Options

Add More Vendors

Edit the Check Email Type node to add vendor-specific keywords:

const customVendors = [
  'your-vendor-name',
  'vendor-domain.com'
];

Modify Status Values

Update the Email Classification and Extraction Agent prompt to add custom status values or change status progression logic.

Add Email Notifications

Insert a Send Email node after database sync to receive notifications for status changes.

Filter by Labels

Configure Gmail Trigger to monitor only specific labels (e.g., β€œOrders”, β€œShopping”).

Multi-Database Support

Duplicate the Notion sync section to route different vendors to separate databases.


Troubleshooting

Email not being classified as order

AI extraction returning empty data

Notion database not updating

Duplicate records being created

Status not updating


Performance Considerations


Privacy & Security


Support & Contributions

Found a bug or have a suggestion? Please open an issue or contribute improvements to this template!


License

This template is provided as-is under the MIT License. Feel free to modify and distribute as needed.


Credits

Created for the n8n community to streamline e-commerce order tracking across multiple platforms.

πŸ”— Nodes Used

Gmail, Gmail Trigger, AI Agent, OpenAI Chat Model, Structured Output Parser, Google Gemini Chat Model

πŸ“₯ Import

Download workflow.json and import into n8n: Workflow menu β†’ Import from File

πŸ“– Importing guide Β· πŸ”‘ Credential setup