1. Opening Problem Statement
Meet Sarah, the inventory manager for a busy Shopify-based online store. Every day, Sarah juggles hundreds of products, and keeping track of which items are running low or sold out is a daunting task. She spends hours manually checking stock levels and updating her team, often missing critical low-stock warnings. This leads to lost sales opportunities, frustrated customers, and unexpected backorders.
Before finding this n8n automation workflow, Sarah’s process was error-prone and time-consuming, costing her at least 3 hours per week just tracking inventory manually. The risk of stockouts slipping through the cracks also meant losing thousands in potential revenue.
2. What This Automation Does
This n8n workflow streamlines Sarah’s inventory monitoring by automatically receiving inventory updates from Shopify and sending real-time alerts to Discord channels when product stock is low or sold out. Here’s exactly what happens when the workflow runs:
- Listens for Shopify’s “Inventory Level Update” webhook to capture changes in product inventory.
- Processes the incoming data to determine if inventory is low (less than 4 units) or completely out of stock.
- Queries Shopify’s GraphQL API to retrieve detailed product information including product title, variant, image, and current inventory quantity.
- Sends a richly formatted alert message with product details and image to a designated Discord channel for low inventory warnings.
- Sends a distinct alert with a red highlight and “Sold Out” notice to a separate Discord channel for out-of-stock products.
- Automates inventory alerting to save hours of manual checking and keeps the whole team instantly informed.
By automating inventory monitoring, Sarah frees up valuable time, reduces human errors, and improves stock replenishment response times.
3. Prerequisites ⚙️
- Shopify account with admin access and webhook permissions.
- n8n automation tool access (cloud or self-hosted).
- Discord account with a bot set up (registered and added to the target channels).
- Shopify GraphQL API credentials (API token with access to inventory and product endpoints).
- Discord Bot credentials configured as preset n8n credentials.
Optional: For self-hosting n8n, consider using Hostinger for reliable service (https://buldrr.com/hostinger).
4. Step-by-Step Guide
Step 1: Set Up Shopify Inventory Webhook
Navigate to your Shopify admin dashboard. Click Settings > Notifications > Webhooks. Click Add webhook, select the event “Inventory Level Update,” set the format to JSON, and enter your n8n webhook URL found in the Webhook node of your workflow. Save it and test by changing some inventory manually. You should see the webhook triggered in n8n.
Common Mistake: Forgetting to use the correct webhook URL or selecting the wrong event type.
Step 2: Configure the n8n Webhook Node
Inside your n8n workflow, locate the Webhook node. It listens for POST requests at a specific URL path matching Shopify’s webhook setup. No special input needed here; just ensure the URL matches exactly as configured in Shopify.
Visual Check: Trigger the webhook by updating an inventory to verify receipt.
Step 3: Identify Inventory Status Using the Code Node
Next, the workflow uses a Code node with JavaScript to analyze inventory availability. Here’s the code:
const available = items[0].json.body.available;
const inventory_item = items[0].json.body.inventory_item_id;
const lowInventory = available > 0 && available < 4;
const outOfStock = available === 0;
return [
{
json: {
available: available,
inventory_tem: inventory_item,
low_inventory: lowInventory,
out_of_stock: outOfStock,
},
},
];It extracts the available quantity and sets flags for low inventory (less than 4) or out of stock. Make sure the field names correspond to Shopify webhook JSON.
Common Mistake: Typos like "inventory_tem" instead of "inventory_item" can cause issues downstream.
Step 4: Use If Nodes to Branch Workflow Based on Inventory Status
Two If nodes named "Low Inventory" and "Out of stock" branch the flow. They check if the flags `low_inventory` and `out_of_stock` are true to decide which path to follow.
Visual Check: You’ll see two outputs from the Code node leading into these conditional checks.
Step 5: Query Shopify with GraphQL for Detailed Product Info
Each branch calls a GraphQL node querying Shopify’s API. The query fetches:
- Product title
- Product variant title
- Inventory quantity
- Product image
The endpoint URL is your store’s GraphQL API endpoint, replace store.myshopify.com with your actual Shopify domain.
GraphQL Query Example:
{
inventoryItem(id: "gid://shopify/InventoryItem/{{ $json.inventory_tem }}") {
id
variant {
id
title
inventoryQuantity
product {
id
title
images(first: 1) {
edges {
node {
originalSrc
}
}
}
}
}
}
}Step 6: Send Alerts via Discord HTTP Request Nodes
Based on the branch, the workflow sends a POST request with a JSON payload to Discord via the HTTP Request nodes. These nodes are configured with your Discord Bot credentials and send richly formatted messages:
- Low Inventory Alert: Yellow embed showing product details and remaining stock.
- Out of Stock Alert: Red embed with "Sold Out" message and product info.
The message includes product images, variant titles, and a footer noting it’s an automated alert.
5. Customizations ✏️
Customize Low Inventory Threshold
In the Code node, change the line const lowInventory = available > 0 && available < 4; to a different number to adjust the threshold when an alert triggers.
Change Alert Channels in Discord
Modify the HTTP Request nodes URLs or credentials to target different Discord channels or servers for low stock and out-of-stock alerts.
Replace Discord with Another Messaging Platform
You can replace the HTTP Request nodes with integrations for Slack, Microsoft Teams, or email by adjusting the payload and endpoints accordingly.
Add More Detailed Product Information
Extend the Shopify GraphQL query to pull additional product metadata such as SKU, vendor, or tags and include them in the alert messages for richer context.
6. Troubleshooting 🔧
Problem: Workflow Not Triggering on Shopify Inventory Update
Cause: Incorrect webhook URL or event not enabled in Shopify.
Solution: Double-check the Webhook URL in Shopify Settings matches n8n’s Webhook node URL exactly. Also, confirm the "Inventory Level Update" event is selected.
Problem: Alert Messages Not Sending to Discord
Cause: Incorrect Discord Bot token or insufficient bot permissions in the channel.
Solution: Validate the Discord Bot credentials in n8n, ensure the bot is invited to the correct Discord server, and has permissions to send messages in the target channel.
Problem: Unexpected JSON Key Errors in Code Node
Cause: Typo or mismatch in JSON key names from Shopify webhook data.
Solution: Inspect the incoming webhook JSON output in n8n’s execution logs and adjust the Code node’s JavaScript to match the actual field names.
7. Pre-Production Checklist ✅
- Verify the Shopify webhook is active and correctly configured.
- Test webhook triggers by adjusting inventory in Shopify and confirming data receipt in n8n.
- Ensure Discord Bot credentials are valid and the bot is active in target channels.
- Confirm GraphQL queries return expected product data in test runs.
- Run test alerts and check the formatting and accuracy of Discord messages.
- Create backups of your workflow configuration for quick rollback.
8. Deployment Guide
Activate your n8n workflow by clicking the Activate button in the n8n editor. Monitor the incoming webhook logs to ensure triggers are firing correctly. Use n8n’s execution history to track message sends and spot any errors.
If you want to scale, consider hosting n8n on a robust cloud service or your own infrastructure for 24/7 availability.
9. FAQs
Can I use Slack instead of Discord for alerts?
Yes, you can replace the Discord HTTP Request nodes with Slack webhook nodes or any other messaging platform API by adjusting payload and endpoints accordingly.
Does this consume Shopify API rate limits?
Yes, each inventory update triggers a GraphQL query. However, Shopify’s webhook throttling combined with n8n’s execution should keep you within reasonable API limits.
Is my inventory data secure in this workflow?
All data flows are secured using HTTPS for both incoming webhooks and outgoing Discord messages. Store your API keys securely in n8n’s credential manager.
10. Conclusion
By building this Shopify inventory alert automation with n8n, you’ve transformed a tedious, error-prone manual process into a real-time, automatic notification system. You’ve saved hours weekly, reduced lost sales from stockouts, and empowered your team with immediate inventory insights.
Next, consider creating alerts for high-selling products, automating purchase order creation, or integrating with your CRM for seamless sales and stock management.
Keep exploring n8n to automate more of your Shopify workflows and make inventory management effortless.