Magento 2低库存提醒通过Slack和Gmail(MSI兼容)
高级
这是一个Miscellaneous领域的自动化工作流,包含 18 个节点。主要使用 If, Code, Gmail, Slack, HttpRequest 等节点。 Magento 2低库存提醒通过Slack和Gmail(MSI兼容)
前置要求
- •Google 账号和 Gmail API 凭证
- •Slack Bot Token 或 Webhook URL
- •可能需要目标 API 的认证凭证
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "54d8e296590faa0bb0e9d6290ad6ee2f19b78aa7b248ecb45c5f7c5ff622d210",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "7d9139ff-f51e-4017-8831-5f8c6c273f51",
"name": "Daily Inventory Check",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-1860,
500
],
"parameters": {
"rule": {
"interval": [
{
"field": "cronExpression",
"expression": "50 8 * * *"
}
]
}
},
"notesInFlow": false,
"typeVersion": 1.2
},
{
"id": "bc8d384a-c5d8-4864-a157-cb21f3643d84",
"name": "Check if Alerts Needed",
"type": "n8n-nodes-base.if",
"position": [
-780,
500
],
"parameters": {
"options": {
"looseTypeValidation": true
},
"conditions": {
"options": {
"version": 1,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "condition-001",
"operator": {
"type": "number",
"operation": "gt"
},
"leftValue": "={{ $node[\"Process Stock Data and Identify Low Stock\"].json[\"lowStockAlerts\"].length > 0 }}",
"rightValue": 0
}
]
}
},
"typeVersion": 2
},
{
"id": "c42fabc3-2180-49e2-8ea5-d24500dbdea0",
"name": "Send Inventory Alert",
"type": "n8n-nodes-base.slack",
"position": [
-20,
340
],
"webhookId": "4d8500c1-7086-4fc8-8b8b-6ff061c4381b",
"parameters": {
"text": "={{ $json.slackMessage }}",
"select": "channel",
"channelId": {
"__rl": true,
"mode": "name",
"value": "#magento-notifications"
},
"otherOptions": {
"includeLinkToWorkflow": false
}
},
"typeVersion": 2.3
},
{
"id": "d0278e03-e2af-48c0-af7c-2be43a504398",
"name": "Workflow Info",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1960,
-140
],
"parameters": {
"width": 420,
"height": 300,
"content": " 📦 MAGENTO 2 STOCK ALERTS\n**Author: Kanaka Kishore Kandregula **\n\nWORKFLOW PURPOSE:\nAutomatically monitor Magento 2 (Adobe Commerce) inventory levels and alert when products are running low\n\nSETUP REQUIREMENTS:\n- Magento 2 store with product inventory tracking\n- Slack & Gmail channels for alerts (#magento-notifications)\n- Define low stock threshold (default: 5 units)\n"
},
"typeVersion": 1
},
{
"id": "f9c6eb47-2f17-4039-b1f0-48ea84ce8b09",
"name": "Features & Config",
"type": "n8n-nodes-base.stickyNote",
"position": [
-600,
-140
],
"parameters": {
"color": 4,
"width": 400,
"height": 300,
"content": " KEY FEATURES\n\n✅ MSI Support\n✅ Daily automated inventory checks\n✅ Customisable stock thresholds\n✅ Multiple SKU Reporting\n✅ Proactive restocking alerts\n\n\n"
},
"typeVersion": 1
},
{
"id": "accd7ae8-f4d7-4bc3-8d99-2e9ecac7ece2",
"name": "Business Value",
"type": "n8n-nodes-base.stickyNote",
"position": [
-160,
-140
],
"parameters": {
"color": 7,
"width": 360,
"height": 300,
"content": " BUSINESS VALUE\n\n🚫 Prevent stockouts\n💰 Maintain sales revenue\n📊 Better inventory management\n⏰ Proactive restocking\n\nTIME TO BUILD: 20 minutes\nDIFFICULTY: Intermediate\nROI: High - prevents lost sales"
},
"typeVersion": 1
},
{
"id": "f3651bdf-d90e-42f5-ba94-3bf4e4c55511",
"name": "Get All Product Skus",
"type": "n8n-nodes-base.httpRequest",
"position": [
-1420,
320
],
"parameters": {
"url": "=https://magekwik.com/rest/V1/products?searchCriteria[pageSize]=0&searchCriteria[filterGroups][0][filters][0][field]=type_id&searchCriteria[filterGroups][0][filters][0][conditionType]=nin&searchCriteria[filterGroups][0][filters][0][value]=configurable,virtual,downloadable&fields=items[sku,extension_attributes[stock_item[manage_stock]]]",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpBearerAuth"
},
"typeVersion": 4.2
},
{
"id": "c20eaa02-c1ce-4999-9aef-8c6a3fd959ee",
"name": "Extract SKUs",
"type": "n8n-nodes-base.code",
"position": [
-1180,
320
],
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nconst skus = [];\nfor (const item of $input.first().json.items) {\n skus.push(item.sku);\n}\nreturn [{ json: { skus: skus } }];"
},
"typeVersion": 2
},
{
"id": "a3fe994f-e782-4c55-8cdb-b8a256acdf37",
"name": "Fetch MSI Stock Status",
"type": "n8n-nodes-base.httpRequest",
"position": [
-1420,
680
],
"parameters": {
"url": "=https://magekwik.com/rest/V1/inventory/source-items?searchCriteria[filterGroups][0][filters][0][field]=sku&searchCriteria[filterGroups][0][filters][0][conditionType]=in&searchCriteria[filterGroups][0][filters][0][value]={{ encodeURIComponent($node[\"Extract SKUs\"].json[\"skus\"].join(',')) }}",
"options": {},
"authentication": "genericCredentialType",
"genericAuthType": "httpBearerAuth"
},
"typeVersion": 4.2
},
{
"id": "2cf2065b-f235-4582-b439-4902a0097e10",
"name": "Process Stock Data and Identify Low Stock",
"type": "n8n-nodes-base.code",
"position": [
-1180,
680
],
"parameters": {
"jsCode": "const lowStockItems = [];\nconst lowStockThreshold = 10; // Define your low stock threshold here\nconst minSourceQuantity = 5; // Define minimum quantity per source if applicable\n\n// Assuming the MSI stock data is in $json.items\nfor (const item of $input.first().json.items) {\n const sku = item.sku;\n const sourceCode = item.source_code;\n const quantity = item.quantity;\n const status = item.status; // 1 for In Stock, 0 for Out of Stock\n\n // Check if the item is in stock and below the overall low stock threshold\n // Or if a specific source is very low\n if (status === 1 && (quantity <= lowStockThreshold || quantity <= minSourceQuantity)) {\n lowStockItems.push({\n sku: sku,\n source: sourceCode,\n quantity: quantity,\n status: status === 1 ? 'In Stock' : 'Out of Stock'\n });\n }\n}\n\n// You can further process lowStockItems to group by SKU or format as needed\n// For now, we'll return a list of individual low stock entries.\nreturn [{ json: { lowStockAlerts: lowStockItems } }];"
},
"typeVersion": 2
},
{
"id": "c92398cf-70f4-4d93-a273-693bc3c1bbd5",
"name": "Send a message",
"type": "n8n-nodes-base.gmail",
"position": [
-20,
620
],
"webhookId": "ff620d7f-3427-4a4f-a945-4cdef714a98b",
"parameters": {
"sendTo": "kmyprojects@gmail.com",
"message": "={{ $json.gmailHtml }}",
"options": {
"appendAttribution": false
},
"subject": "={{ $json.subjectLine }}"
},
"typeVersion": 2.1
},
{
"id": "55ffa452-f2c5-43c2-996d-0f0fb7c9bed4",
"name": "Format Message",
"type": "n8n-nodes-base.code",
"position": [
-480,
500
],
"parameters": {
"jsCode": "const lowStockAlerts = Array.isArray($input.first().json.lowStockAlerts) ? $input.first().json.lowStockAlerts : [];\n\nlet plainText = \"*📦 Low Stock Alert for Magento 2 Multi-Store (MSI)*\\n\\n\";\nlet htmlText = \"<b>📦 Low Stock Alert for Magento 2 Multi-Store (MSI)</b><br><br>\";\n\nif (lowStockAlerts.length === 0) {\n plainText += \"_No low stock items found at this time._\";\n htmlText += \"<i>No low stock items found at this time.</i>\";\n} else {\n plainText += \"*The following products have low stock:*\\n\\n\";\n htmlText += \"<b>The following products have low stock:</b><br><br>\";\n\n // Text version\n plainText += \"```\\nSKU Source Quantity Status\\n\";\n plainText += \"-------- --------- -------- --------\\n\";\n\n // HTML table version\n htmlText += `<table border=\"1\" cellpadding=\"6\" cellspacing=\"0\" style=\"border-collapse: collapse;\">\n <thead>\n <tr>\n <th align=\"left\">SKU</th>\n <th align=\"left\">Source</th>\n <th align=\"left\">Quantity</th>\n <th align=\"left\">Status</th>\n </tr>\n </thead>\n <tbody>\n `;\n\n lowStockAlerts.forEach(item => {\n const sku = item.sku || 'N/A';\n const source = item.source || 'N/A';\n const quantity = item.quantity || 0;\n const status = item.status || 'Unknown';\n\n // Plain text table row\n plainText += `${sku.padEnd(10)}${source.padEnd(11)}${String(quantity).padEnd(9)}${status}\\n`;\n\n // HTML table row\n htmlText += `<tr>\n <td>${sku}</td>\n <td>${source}</td>\n <td>${quantity}</td>\n <td>${status}</td>\n </tr>`;\n });\n\n plainText += \"```\\n\\n🔍 Please check your Magento 2 inventory.\";\n htmlText += \"</tbody></table><br><br>🔍 <b>Please check your Magento 2 inventory.</b>\";\n}\n\n// Output both formats\nreturn [{\n json: {\n slackMessage: plainText,\n gmailHtml: htmlText,\n subjectLine: `🔔 Magento 2 Low Stock Alert – ${new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })}`\n }\n}];\n"
},
"typeVersion": 2
},
{
"id": "974a2ff6-768b-44b4-bf14-7b8534c99eac",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1500,
-140
],
"parameters": {
"color": 5,
"width": 420,
"height": 300,
"content": " WORK FLOW\n\n1. Schedule Trigger (daily 8:50 AM check)\n2. Magento 2 (get all products)\n3. Code Node (filter low stock items)\n4. If Node (check if any alerts needed)\n5. Format alert message\n6. Slack & Gmail (send inventory alert)"
},
"typeVersion": 1
},
{
"id": "0d19935c-9078-435a-a940-49fdfef93bef",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1040,
-140
],
"parameters": {
"color": 3,
"width": 400,
"height": 300,
"content": " CONFIGURATION NOTES\n\n- Adjust lowStockThreshold variable in Process Stock Data node\n- Modify daily schedule timing as needed\n- You Bearer Token from Magento\n- Slack & Gmail API details"
},
"typeVersion": 1
},
{
"id": "cde3e885-dad8-4467-840a-52dbfd0997e1",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1940,
400
],
"parameters": {
"color": 7,
"width": 280,
"height": 300,
"content": " Trigs Daily 8:50am"
},
"typeVersion": 1
},
{
"id": "ca9ffce4-f84c-4da1-aa0c-5b50812fe8ff",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1520,
220
],
"parameters": {
"color": 5,
"width": 540,
"height": 660,
"content": " Magento Logic"
},
"typeVersion": 1
},
{
"id": "a563ff82-2b81-468b-a33f-0780c9522a4c",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-120,
220
],
"parameters": {
"color": 4,
"width": 320,
"height": 660,
"content": " Notifications"
},
"typeVersion": 1
},
{
"id": "70c8982e-ea87-4d75-8a69-ee6ad174b4c1",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-820,
400
],
"parameters": {
"color": 6,
"width": 520,
"height": 300,
"content": " Checks & Message Formatting"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"c20eaa02-c1ce-4999-9aef-8c6a3fd959ee": {
"main": [
[
{
"node": "a3fe994f-e782-4c55-8cdb-b8a256acdf37",
"type": "main",
"index": 0
}
]
]
},
"55ffa452-f2c5-43c2-996d-0f0fb7c9bed4": {
"main": [
[
{
"node": "c42fabc3-2180-49e2-8ea5-d24500dbdea0",
"type": "main",
"index": 0
},
{
"node": "c92398cf-70f4-4d93-a273-693bc3c1bbd5",
"type": "main",
"index": 0
}
]
]
},
"f3651bdf-d90e-42f5-ba94-3bf4e4c55511": {
"main": [
[
{
"node": "c20eaa02-c1ce-4999-9aef-8c6a3fd959ee",
"type": "main",
"index": 0
}
]
]
},
"7d9139ff-f51e-4017-8831-5f8c6c273f51": {
"main": [
[
{
"node": "f3651bdf-d90e-42f5-ba94-3bf4e4c55511",
"type": "main",
"index": 0
}
]
]
},
"bc8d384a-c5d8-4864-a157-cb21f3643d84": {
"main": [
[
{
"node": "55ffa452-f2c5-43c2-996d-0f0fb7c9bed4",
"type": "main",
"index": 0
}
]
]
},
"a3fe994f-e782-4c55-8cdb-b8a256acdf37": {
"main": [
[
{
"node": "2cf2065b-f235-4582-b439-4902a0097e10",
"type": "main",
"index": 0
}
]
]
},
"2cf2065b-f235-4582-b439-4902a0097e10": {
"main": [
[
{
"node": "bc8d384a-c5d8-4864-a157-cb21f3643d84",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 杂项
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
通过Gmail审批自动禁用一年未售出的Magento 2产品
通过Gmail审批自动禁用一年未售出的Magento 2产品
If
Code
Gmail
+
If
Code
Gmail
22 节点Kanaka Kishore Kandregula
文档提取
使用 HTTP Last-Modified 检查从 Google Sheets 获取职位发布过期和刷新提醒
通过 Google Sheets、HTTP 检查和 Gmail 实现职位发布过期提醒的自动化
If
Set
Code
+
If
Set
Code
19 节点WeblineIndia
人力资源
供应商风险评分自动化
使用D&B、NewsAPI和Gmail提醒自动化供应商风险评分
If
Set
Code
+
If
Set
Code
16 节点Rodrigue
杂项
Magento 2 产品与优惠券自动提醒到 Telegram(防重复)
Magento 2 产品与优惠券自动提醒到 Telegram(防重复保护)
If
Code
My Sql
+
If
Code
My Sql
27 节点Kanaka Kishore Kandregula
社交媒体
比特币和以太坊加密货币下跌警报(Telegram、Slack 和 SMS)
通过 Telegram、Slack 和 SMS 发送比特币和以太坊加密货币下跌警报
If
Code
Slack
+
If
Code
Slack
8 节点David Olusola
加密货币交易
使用Groq、Gemini和Slack审批系统自动化RSS到Medium发布
通过Groq、Gemini和Slack审批系统实现RSS到Medium发布的自动化流程
If
Set
Code
+
If
Set
Code
41 节点ObisDev
内容创作
工作流信息
难度等级
高级
节点数量18
分类1
节点类型7
作者
Kanaka Kishore Kandregula
@kmyprojectsExperienced 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.
外部链接
在 n8n.io 查看 →
分享此工作流