Most Shopify merchants spend hours each week on tasks that are perfectly suited to automation: checking which products are running low, generating sales reports for stakeholders, responding to routine customer service patterns, and pulling data across multiple tools into one place.
AI agents can handle all of this. Unlike traditional automation that follows rigid if-then rules, AI agents can interpret context, make reasonable judgements, and produce natural-language outputs that don’t require a developer to read or action.
This guide shows you four practical AI agent workflows for Shopify — inventory alerts, reorder automation, daily sales summaries, and customer segmentation — built using n8n (self-hosted or cloud) with Shopify’s Admin API.
What You Need
- Shopify store (any plan — these use the Admin API, available on all plans)
- Shopify API access token — generated in Shopify Admin → Settings → Apps and sales channels → Develop apps → create a custom app with required scopes
- n8n — self-hosted or n8n cloud (free tier available)
- OpenAI or Anthropic API key — for the AI summary/interpretation nodes
Required Shopify API scopes for these workflows:
read_products— product and variant dataread_inventory— inventory levelsread_orders— order datawrite_draft_orders— if automating purchase orders
Workflow 1: Low Inventory Alert with AI Context
What it does: Runs daily, checks inventory across all products, and sends a Slack message that not only lists low-stock items but includes an AI-generated assessment of urgency based on recent sales velocity.
A traditional inventory alert just says “Product X has 3 units left.” This agent says “Product X has 3 units left and has been selling an average of 2 units/day over the past 7 days — you have approximately 1.5 days of stock remaining. This is the 3rd time this product has hit low stock in 60 days.”
Step 1: Get Inventory Levels from Shopify
HTTP Request node → Shopify Admin API
Endpoint: GET /admin/api/2024-10/products.json?limit=250
Or for inventory-specific data:
Endpoint: GET /admin/api/2024-10/inventory_levels.json?location_ids=YOUR_LOCATION_ID
Set up Shopify credentials in n8n:
- Auth type: Header Auth
- Header name:
X-Shopify-Access-Token - Header value: your Admin API access token
Code node to process inventory:
const products = $json.products;
const threshold = 10; // flag items with < 10 units
const lowStockItems = [];
for (const product of products) {
for (const variant of product.variants) {
if (variant.inventory_management === 'shopify' &&
variant.inventory_quantity < threshold &&
variant.inventory_quantity >= 0) {
lowStockItems.push({
product_id: product.id,
product_title: product.title,
variant_title: variant.title !== 'Default Title' ? variant.title : null,
sku: variant.sku,
quantity: variant.inventory_quantity,
product_url: `https://admin.shopify.com/store/YOUR_STORE/products/${product.id}`
});
}
}
}
// Sort by urgency (lowest stock first)
lowStockItems.sort((a, b) => a.quantity - b.quantity);
return { lowStockItems, count: lowStockItems.length };
Step 2: Fetch Recent Sales for Context
For each low-stock item, fetch its order history to calculate sales velocity:
// Build a summary string for the AI node
const itemSummaries = $json.lowStockItems.map(item => {
return `${item.product_title}${item.variant_title ? ' - ' + item.variant_title : ''}: ${item.quantity} units remaining (SKU: ${item.sku || 'N/A'})`;
}).join('\n');
return {
summary: itemSummaries,
count: $json.count,
date: new Date().toLocaleDateString('en-GB')
};
Step 3: AI Node — Generate the Alert
Prompt:
You are a Shopify inventory manager. Based on the following low-stock items, write a brief, direct Slack alert.
For each item, estimate urgency (Critical/High/Medium) based on remaining quantity.
Use this scale: Critical = under 5 units, High = 5-7 units, Medium = 8-10 units.
Be concise. Use bullet points. End with a single action recommendation.
Low stock items ({{ $json.count }} total) — {{ $json.date }}:
{{ $json.summary }}
Step 4: Slack Notification
Post to your inventory management channel with the AI-generated alert text.
Workflow 2: Automated Reorder Draft with Supplier Data
What it does: When a product hits a critical threshold (e.g., under 5 units), the agent creates a draft purchase order summary, looks up the supplier contact from a Google Sheet or Airtable, and sends a pre-drafted email to the supplier.
Setup
You’ll need a supplier reference spreadsheet (Google Sheets works well) with columns:
- SKU | Supplier Name | Supplier Email | Lead Time (days) | Min Order Qty | Unit Cost
n8n Workflow Structure
Trigger (Schedule or Webhook) →
Shopify: Get inventory →
Filter: Only critical stock (<5 units) →
Google Sheets: Look up supplier by SKU →
Code: Build order details →
AI: Write supplier email →
Gmail: Send to supplier
AI node prompt for the supplier email:
Write a professional purchase order request email to a supplier.
Tone: Professional but brief.
Include: Product name, SKU, quantity needed, requested delivery date (today + lead time days).
Sign off as "Inventory Management Team, [Your Store Name]"
Order details:
Product: {{ $json.product_title }}
SKU: {{ $json.sku }}
Current stock: {{ $json.current_quantity }} units
Quantity to order: {{ $json.reorder_quantity }}
Supplier: {{ $json.supplier_name }}
Lead time: {{ $json.lead_time_days }} days
Requested delivery by: {{ $json.requested_delivery }}
Write the email body only (no subject line). Keep it under 150 words.
Workflow 3: Daily Sales Summary with AI Commentary
What it does: Every morning, pulls yesterday’s Shopify orders, calculates key metrics, fetches the top-selling products, and sends an AI-narrated summary to email or Slack.
Fetch Yesterday’s Orders
HTTP Request → GET /admin/api/2024-10/orders.json
Query params:
status: any
created_at_min: [yesterday 00:00:00]
created_at_max: [yesterday 23:59:59]
limit: 250
Code node to calculate metrics:
const orders = $json.orders.filter(o => o.financial_status !== 'refunded');
const metrics = {
order_count: orders.length,
gross_revenue: orders.reduce((sum, o) => sum + parseFloat(o.total_price), 0).toFixed(2),
average_order_value: orders.length > 0
? (orders.reduce((sum, o) => sum + parseFloat(o.total_price), 0) / orders.length).toFixed(2)
: 0,
refunds: $json.orders.filter(o => o.financial_status === 'refunded').length,
new_customers: orders.filter(o => o.customer?.orders_count === 1).length,
returning_customers: orders.filter(o => o.customer?.orders_count > 1).length,
};
// Count products sold
const productCounts = {};
for (const order of orders) {
for (const item of order.line_items) {
const key = item.title;
productCounts[key] = (productCounts[key] || 0) + item.quantity;
}
}
const topProducts = Object.entries(productCounts)
.sort((a, b) => b[1] - a[1])
.slice(0, 5)
.map(([name, qty]) => `${name}: ${qty} sold`);
return { metrics, topProducts, date: new Date().toLocaleDateString('en-GB') };
AI node prompt:
You are an ecommerce analyst. Write a 2-paragraph daily sales summary for a Shopify store.
Paragraph 1: Summarise overall performance in plain English. Highlight anything notable.
Paragraph 2: Comment on the top products and customer split (new vs returning). End with one observation or question worth investigating.
Use British English. Be concise and direct — this is read by a busy business owner.
Yesterday's data ({{ $json.date }}):
Orders: {{ $json.metrics.order_count }}
Revenue: £{{ $json.metrics.gross_revenue }}
AOV: £{{ $json.metrics.average_order_value }}
New customers: {{ $json.metrics.new_customers }}
Returning customers: {{ $json.metrics.returning_customers }}
Refunds: {{ $json.metrics.refunds }}
Top 5 products:
{{ $json.topProducts.join('\n') }}
Workflow 4: Customer Segmentation for Email Campaigns
What it does: Queries Shopify customer data, segments customers into groups (high-value, at-risk, new), and generates a campaign brief for each segment that your email marketing tool can use.
Segment Definitions
const customers = $json.customers;
const now = new Date();
const segments = {
high_value: [], // 3+ orders, spent £500+
at_risk: [], // previously active, no order in 90+ days
new: [], // 1 order, within 30 days
one_time: [] // 1 order, older than 30 days
};
for (const customer of customers) {
const orderCount = customer.orders_count;
const totalSpent = parseFloat(customer.total_spent);
const lastOrderDate = new Date(customer.updated_at);
const daysSinceOrder = (now - lastOrderDate) / (1000 * 60 * 60 * 24);
if (orderCount >= 3 && totalSpent >= 500) {
segments.high_value.push(customer);
} else if (orderCount >= 2 && daysSinceOrder > 90) {
segments.at_risk.push(customer);
} else if (orderCount === 1 && daysSinceOrder <= 30) {
segments.new.push(customer);
} else if (orderCount === 1 && daysSinceOrder > 30) {
segments.one_time.push(customer);
}
}
return {
high_value_count: segments.high_value.length,
at_risk_count: segments.at_risk.length,
new_count: segments.new.length,
one_time_count: segments.one_time.length
};
AI node for campaign brief:
You are an email marketing strategist. Write a brief campaign recommendation for each customer segment.
For each segment, write:
- Subject line (5-8 words)
- One-sentence email goal
- Key message (2 sentences)
- Suggested offer (if any)
Segments:
- High Value ({{ $json.high_value_count }} customers): 3+ orders, £500+ spent
- At Risk ({{ $json.at_risk_count }} customers): Previously active, no purchase in 90+ days
- New ({{ $json.new_count }} customers): First purchase in last 30 days
- One-Time ({{ $json.one_time_count }} customers): Single purchase, 30+ days ago
Store sells: [your product category]
Brand tone: [professional/casual/playful]
Connecting to Make.com Instead of n8n
All four workflows above can also be built in Make.com (formerly Integromat). Key differences:
- Shopify module is built-in — no need to build HTTP requests manually
- AI module (OpenAI or Anthropic) is available in the library
- Visual interface is more approachable for non-developers
- Pricing is per operation (each API call counts) rather than per workflow
For the inventory alert workflow in Make.com:
- Shopify → Watch Products or List Products module
- Filter module — quantity less than threshold
- OpenAI → Create a Completion module with your prompt
- Slack → Create a Message module
The logic is identical; only the interface differs.
How Far to Push Automation
A practical rule: automate decisions where the cost of being wrong is low (sending a Slack alert, drafting an email) and keep humans in the loop for decisions where errors are expensive (actually placing a supplier order, deleting customer records, issuing refunds).
The workflows above either notify humans (alerts and summaries) or create drafts for review (purchase order emails) — they don’t take irreversible actions autonomously. That’s the right level of automation for most Shopify operations.
We build custom Shopify automation workflows — inventory management, reporting, multi-channel data pipelines, and customer lifecycle automation. Book a free consultation to discuss what your team spends time on that could be automated.