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": "每日库存检查",
"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": "检查是否需要警报",
"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": "发送库存警报",
"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": "工作流信息",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1960,
-140
],
"parameters": {
"width": 420,
"height": 300,
"content": "📦 MAGENTO 2 库存警报"
},
"typeVersion": 1
},
{
"id": "f9c6eb47-2f17-4039-b1f0-48ea84ce8b09",
"name": "功能与配置",
"type": "n8n-nodes-base.stickyNote",
"position": [
-600,
-140
],
"parameters": {
"color": 4,
"width": 400,
"height": 300,
"content": "主要功能"
},
"typeVersion": 1
},
{
"id": "accd7ae8-f4d7-4bc3-8d99-2e9ecac7ece2",
"name": "商业价值",
"type": "n8n-nodes-base.stickyNote",
"position": [
-160,
-140
],
"parameters": {
"color": 7,
"width": 360,
"height": 300,
"content": "商业价值"
},
"typeVersion": 1
},
{
"id": "f3651bdf-d90e-42f5-ba94-3bf4e4c55511",
"name": "获取所有产品 SKU",
"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": "提取 SKU",
"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": "获取 MSI 库存状态",
"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": "处理库存数据并识别低库存",
"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": "发送消息",
"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": "格式化消息",
"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": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1500,
-140
],
"parameters": {
"color": 5,
"width": 420,
"height": 300,
"content": "工作流程"
},
"typeVersion": 1
},
{
"id": "0d19935c-9078-435a-a940-49fdfef93bef",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1040,
-140
],
"parameters": {
"color": 3,
"width": 400,
"height": 300,
"content": "配置说明"
},
"typeVersion": 1
},
{
"id": "cde3e885-dad8-4467-840a-52dbfd0997e1",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1940,
400
],
"parameters": {
"color": 7,
"width": 280,
"height": 300,
"content": "每日上午 8:50 触发"
},
"typeVersion": 1
},
{
"id": "ca9ffce4-f84c-4da1-aa0c-5b50812fe8ff",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1520,
220
],
"parameters": {
"color": 5,
"width": 540,
"height": 660,
"content": "Magento 逻辑"
},
"typeVersion": 1
},
{
"id": "a563ff82-2b81-468b-a33f-0780c9522a4c",
"name": "便签4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-120,
220
],
"parameters": {
"color": 4,
"width": 320,
"height": 660,
"content": "通知"
},
"typeVersion": 1
},
{
"id": "70c8982e-ea87-4d75-8a69-ee6ad174b4c1",
"name": "便利贴5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-820,
400
],
"parameters": {
"color": 6,
"width": 520,
"height": 300,
"content": "检查与消息格式化"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Extract SKUs": {
"main": [
[
{
"node": "Fetch MSI Stock Status",
"type": "main",
"index": 0
}
]
]
},
"Format Message": {
"main": [
[
{
"node": "Send Inventory Alert",
"type": "main",
"index": 0
},
{
"node": "Send a message",
"type": "main",
"index": 0
}
]
]
},
"Get All Product Skus": {
"main": [
[
{
"node": "Extract SKUs",
"type": "main",
"index": 0
}
]
]
},
"Daily Inventory Check": {
"main": [
[
{
"node": "Get All Product Skus",
"type": "main",
"index": 0
}
]
]
},
"Check if Alerts Needed": {
"main": [
[
{
"node": "Format Message",
"type": "main",
"index": 0
}
]
]
},
"Fetch MSI Stock Status": {
"main": [
[
{
"node": "Process Stock Data and Identify Low Stock",
"type": "main",
"index": 0
}
]
]
},
"Process Stock Data and Identify Low Stock": {
"main": [
[
{
"node": "Check if Alerts Needed",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个高级难度的工作流,适用于Miscellaneous等场景。适合高级用户,包含 16+ 个节点的复杂工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
通过Gmail审批自动禁用一年未售出的Magento 2产品
通过Gmail审批自动禁用一年未售出的Magento 2产品
If
Code
Gmail
+7
22 节点Kanaka Kishore Kandregula
Document Extraction
使用 HTTP Last-Modified 检查从 Google Sheets 获取职位发布过期和刷新提醒
通过 Google Sheets、HTTP 检查和 Gmail 实现职位发布过期提醒的自动化
If
Set
Code
+6
19 节点WeblineIndia
HR
供应商风险评分自动化
使用D&B、NewsAPI和Gmail提醒自动化供应商风险评分
If
Set
Code
+6
16 节点Rodrigue
Miscellaneous
Magento 2 产品与优惠券自动提醒到 Telegram(防重复)
Magento 2 产品与优惠券自动提醒到 Telegram(防重复保护)
If
Code
My Sql
+5
27 节点Kanaka Kishore Kandregula
Social Media
比特币和以太坊加密货币下跌警报(Telegram、Slack 和 SMS)
通过 Telegram、Slack 和 SMS 发送比特币和以太坊加密货币下跌警报
If
Code
Slack
+5
8 节点David Olusola
Crypto Trading
使用 CoinGecko 通过邮件/SMS 监控比特币和以太坊价格告警
使用 CoinGecko 通过邮件/SMS 监控比特币和以太坊价格告警
If
Code
Gmail
+4
8 节点David Olusola
Crypto Trading
工作流信息
难度等级
高级
节点数量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 上查看 →
分享此工作流