Order Updated Event
Documentation for the order.updated webhook event
The order.updated event is triggered whenever an existing order is modified.
Event Type
order.updatedWhen It's Triggered
This event is sent when:
- Order status changes (e.g., PENDING → PROCESSING → SHIPPED)
- Customer information is updated
- Delivery address is modified
- Order items are added, removed, or quantities changed
- Payment information is updated
- Notes or special instructions are modified
- Delivery charges are adjusted
Webhook Payload Structure
The payload structure is identical to the order.created event, containing the complete updated order data:
{
"event": "order.updated",
"timestamp": "2026-02-15T14:45:00.000Z",
"data": {
"orderGroupId": "og_abc123xyz",
"orderGroupCode": "ORD-2026-001",
"deliveryCharge": 50,
"advancedPayment": 500,
"advancedPaymentId": "pay_xyz789",
"customer": {
"id": "cust_123",
"name": "John Doe",
"email": "john@example.com",
"phoneNumber": "+1234567890",
"shippingAddress": "456 New Address, City, Country"
},
"status": "PROCESSING",
"paymentMethods": [{ "id": "pm_abc1", "name": "bKash" }],
"purchaseIntent": "PURCHASED",
"platform": "MESSENGER",
"facebookPageId": "page_123",
"whatsappAccountId": null,
"totalQuantity": 3,
"orderCount": 2,
"createdAt": "2026-02-15T10:30:00.000Z",
"updatedAt": "2026-02-15T14:45:00.000Z",
"dateTime": "2026-02-15T10:30:00.000Z",
"notes": "Customer prefers morning delivery. Updated address.",
"orders": [
{
"id": "item_1",
"productId": "prod_abc",
"productName": "Wireless Headphones",
"variant": "Black",
"quantity": 2,
"extra": {
"color": "Midnight Black",
"engraving": "John D."
},
"productImages": ["https://example.com/image1.jpg"],
"product": {
"id": "prod_abc",
"name": "Wireless Headphones",
"retailPrice": 2500,
"wholesalePrice": 2000,
"soldPrice": 2300,
"description": "Premium wireless headphones with noise cancellation",
"images": ["https://example.com/image1.jpg"]
}
}
]
}
}Field Descriptions
All fields are identical to the Order Created Event. The event field will be "order.updated" and the updatedAt timestamp will reflect when the change occurred.
Key Differences from order.created
- The
updatedAtfield will be more recent thancreatedAt - The order data reflects the current state after modifications
- You'll need to compare with your stored data to identify what changed
Detecting Changes
Since the webhook payload contains the complete order data (not just changes), you'll need to compare it with your stored order to identify what changed:
async function handleOrderUpdated(newData) {
// Fetch existing order from your database
const existingOrder = await db.orders.findUnique({
where: { orderGroupId: newData.orderGroupId },
});
// Detect status change
if (existingOrder.status !== newData.status) {
console.log(`Status changed: ${existingOrder.status} → ${newData.status}`);
await handleStatusChange(newData, existingOrder.status, newData.status);
}
// Detect address change
if (
existingOrder.customer.shippingAddress !== newData.customer.shippingAddress
) {
console.log('Shipping address updated');
await handleAddressChange(newData);
}
// Detect item changes
const oldQuantity = existingOrder.totalQuantity;
const newQuantity = newData.totalQuantity;
if (oldQuantity !== newQuantity) {
console.log(`Quantity changed: ${oldQuantity} → ${newQuantity}`);
await handleInventoryAdjustment(existingOrder, newData);
}
// Detect extra property changes on individual items
for (const newItem of newData.orders) {
const oldItem = existingOrder.orders.find((i) => i.id === newItem.id);
if (
oldItem &&
JSON.stringify(oldItem.extra) !== JSON.stringify(newItem.extra)
) {
console.log(
`Extra properties changed for item ${newItem.id}:`,
newItem.extra,
);
await handleExtraPropertiesChange(newItem);
}
}
// Update your database
await db.orders.update({
where: { orderGroupId: newData.orderGroupId },
data: newData,
});
}Example Handlers
Track Status Changes
async function handleStatusChange(orderData, oldStatus, newStatus) {
const statusFlow = {
PENDING: 'Order received',
PROCESSING: 'Order is being prepared',
SHIPPED: 'Order has been shipped',
DELIVERED: 'Order delivered successfully',
CANCELLED: 'Order cancelled',
RETURNED: 'Order returned',
};
// Notify customer
if (orderData.customer.email) {
await emailService.send({
to: orderData.customer.email,
template: 'status-update',
data: {
orderCode: orderData.orderGroupCode,
oldStatus: statusFlow[oldStatus],
newStatus: statusFlow[newStatus],
order: orderData,
},
});
}
// Send SMS for important updates
if (
['SHIPPED', 'DELIVERED'].includes(newStatus) &&
orderData.customer.phoneNumber
) {
await smsService.send({
to: orderData.customer.phoneNumber,
message: `Order ${orderData.orderGroupCode} ${statusFlow[newStatus]}`,
});
}
// Track in analytics
await analytics.track({
event: 'Order Status Changed',
properties: {
orderId: orderData.orderGroupId,
oldStatus,
newStatus,
platform: orderData.platform,
},
});
}Handle Inventory Adjustments
async function handleInventoryAdjustment(oldOrder, newOrder) {
// Create maps for easy comparison
const oldItems = new Map(
oldOrder.orders.map((item) => [item.productId, item.quantity]),
);
const newItems = new Map(
newOrder.orders.map((item) => [item.productId, item.quantity]),
);
// Check for quantity changes
for (const [productId, newQty] of newItems) {
const oldQty = oldItems.get(productId) || 0;
const diff = newQty - oldQty;
if (diff !== 0) {
await db.inventory.increment({
where: { productId },
data: { quantity: -diff },
});
console.log(
`Inventory adjusted for ${productId}: ${diff > 0 ? '+' : ''}${diff}`,
);
}
}
// Check for removed items (restore inventory)
for (const [productId, oldQty] of oldItems) {
if (!newItems.has(productId)) {
await db.inventory.increment({
where: { productId },
data: { quantity: oldQty },
});
console.log(`Inventory restored for ${productId}: +${oldQty}`);
}
}
}Update Shipping Provider
async function handleOrderUpdated(orderData) {
// If address changed and order is already shipped, notify carrier
const existingOrder = await getExistingOrder(orderData.orderGroupId);
if (
orderData.status === 'SHIPPED' &&
existingOrder.customer.shippingAddress !==
orderData.customer.shippingAddress
) {
await shippingProvider.updateAddress({
trackingNumber: orderData.trackingNumber,
newAddress: orderData.customer.shippingAddress,
});
// Notify customer
await emailService.send({
to: orderData.customer.email,
template: 'address-update-confirmation',
data: {
orderCode: orderData.orderGroupCode,
newAddress: orderData.customer.shippingAddress,
},
});
}
}Common Use Cases
1. Status-Based Workflows
Trigger different actions based on status changes:
const statusHandlers = {
PROCESSING: async (order) => {
await notifyWarehouse(order);
await generatePickingList(order);
},
SHIPPED: async (order) => {
await sendTrackingInfo(order);
await updateExpectedDeliveryDate(order);
},
DELIVERED: async (order) => {
await requestReview(order);
await markAsComplete(order);
},
CANCELLED: async (order) => {
await refundPayment(order);
await restoreInventory(order);
},
};
async function handleOrderUpdated(orderData) {
const handler = statusHandlers[orderData.status];
if (handler) {
await handler(orderData);
}
}2. Real-time Customer Updates
Keep customers informed of changes:
async function notifyCustomerOfUpdate(oldOrder, newOrder) {
const changes = [];
if (oldOrder.status !== newOrder.status) {
changes.push(`Status: ${oldOrder.status} → ${newOrder.status}`);
}
if (oldOrder.customer.shippingAddress !== newOrder.customer.shippingAddress) {
changes.push('Shipping address updated');
}
if (oldOrder.totalQuantity !== newOrder.totalQuantity) {
changes.push('Order items modified');
}
if (changes.length > 0 && newOrder.customer.email) {
await emailService.send({
to: newOrder.customer.email,
subject: `Order ${newOrder.orderGroupCode} Updated`,
template: 'order-update',
data: {
order: newOrder,
changes: changes,
},
});
}
}3. Sync with External Systems
Keep third-party systems in sync:
async function syncWithERP(orderData) {
try {
await erpSystem.updateOrder({
externalId: orderData.orderGroupId,
status: orderData.status,
items: orderData.orders.map((item) => ({
sku: item.productId,
quantity: item.quantity,
name: item.productName,
})),
customer: {
name: orderData.customer.name,
email: orderData.customer.email,
phone: orderData.customer.phoneNumber,
address: orderData.customer.shippingAddress,
},
updatedAt: orderData.updatedAt,
});
} catch (error) {
console.error('Failed to sync with ERP:', error);
await logSyncError(orderData.orderGroupId, error);
}
}4. Audit Trail
Maintain a complete history of order changes:
async function maintainAuditTrail(oldOrder, newOrder) {
const changes = compareOrders(oldOrder, newOrder);
await db.orderAuditLog.create({
data: {
orderGroupId: newOrder.orderGroupId,
timestamp: newOrder.updatedAt,
changes: changes,
previousState: oldOrder,
newState: newOrder,
},
});
}
function compareOrders(oldOrder, newOrder) {
const changes = [];
// Compare all fields and track changes
Object.keys(newOrder).forEach((key) => {
if (JSON.stringify(oldOrder[key]) !== JSON.stringify(newOrder[key])) {
changes.push({
field: key,
oldValue: oldOrder[key],
newValue: newOrder[key],
});
}
});
return changes;
}Best Practices
1. Store Previous State
Always compare with the previous state to identify changes:
// Store a copy before processing
await redis.set(
`order:${orderData.orderGroupId}:previous`,
JSON.stringify(orderData),
'EX',
86400, // 24 hours
);2. Handle Partial Updates
Be prepared for the fact that any field might have changed:
function safeCompare(oldValue, newValue, handler) {
if (oldValue !== newValue) {
handler(oldValue, newValue);
}
}3. Idempotency
Use updatedAt timestamp to prevent processing old updates:
async function handleOrderUpdated(orderData) {
const existing = await getExistingOrder(orderData.orderGroupId);
if (new Date(existing.updatedAt) >= new Date(orderData.updatedAt)) {
console.log('Received outdated update, skipping');
return;
}
// Process update
}