Webhooks
Webhook = ระบบ WMS "โทรหา" URL ของคุณเมื่อเกิดเหตุการณ์ที่กำหนด
คืออะไร?
เปลี่ยนจาก "ระบบอื่นต้องมา Pull WMS" → เป็น "WMS Push ไปบอกระบบอื่นทันทีเมื่อเกิดเหตุการณ์"
เช่น:
- มี Order ใหม่ → Push ไป ERP
- Shipment ส่งออก → Push ไป Notification system
- Stock ต่ำกว่า Min → Push ไป Procurement
วิธีเข้าหน้า Webhooks
Sidebar (Admin) → Webhooks
สร้าง Webhook
- + New Webhook
- กรอก:
- Name — เช่น
ERP_Order_Sync - Target URL —
https://erp.your-company.com/webhooks/wms - Events — เลือกหลายอันได้:
order.createdorder.shippedinventory.low_stockgrn.confirmed- ฯลฯ
- Secret — ใช้ HMAC verify (แนะนำ)
- Headers (ทางเลือก) — Custom headers
- Name — เช่น
- Save
รูปแบบ Payload
json
{
"id": "evt_2026_001234",
"type": "order.shipped",
"timestamp": "2026-05-29T14:32:11Z",
"data": {
"order_id": "ORD-2026-1234",
"customer": "CUST-001",
"tracking": "FLASH123456",
"items": [...]
}
}ใส่ HMAC signature ใน Header:
X-WMS-Signature: sha256=abc123...Verify Signature
ฝั่งผู้รับ:
js
const expected = hmac('sha256', secret).update(body).digest('hex')
if (expected !== receivedSignature) throw 'Invalid'Delivery + Retry
ถ้า Endpoint ตอบ:
- 2xx — Success ✅
- 4xx / 5xx / timeout — Retry
Retry policy:
- 5 ครั้ง
- Backoff: 30s, 2m, 10m, 1h, 6h
- หลังจากนั้น → Failed (ต้อง resend manually)
ดู Delivery Log
ในแต่ละ Webhook → Tab Deliveries:
- Timestamp
- Event Type
- Response Code
- Response Body (ถ้า fail)
- Latency
- Retry count
Resend Manually
หาก fail แต่ Endpoint แก้แล้ว:
- เปิด Delivery → กด Resend
Test Webhook
- เปิด Webhook → Send Test Event
- ระบบส่ง dummy payload
- Verify ที่ Endpoint ของคุณ
Events ที่มี
Inventory
stock.changedinventory.low_stockinventory.expiring_soon
Inbound
asn.createdgrn.createdgrn.confirmedputaway.completed
Outbound
order.createdorder.allocatedwave.releasedpick.completedshipment.shippedshipment.delivered
Returns
rma.requestedrma.approvedrma.received
Admin
user.createdaudit.alert
Best Practices
- Idempotent receiver — รับ event เดิม 2 ครั้งไม่ทำซ้ำ (ใช้ event ID เป็น dedup key)
- Response เร็ว — 2xx ภายใน 5 วินาที (อย่าทำงานหนักก่อน respond)
- Verify signature ทุกครั้ง
- Monitor failed deliveries — alert ทันที