Developer
Shipment Cancelled Event
Documentation for the shipment.cancelled webhook event
The shipment.cancelled event is triggered when a shipment is cancelled before or during delivery.
Event Type
shipment.cancelledWhen It's Triggered
This event is sent when:
- Customer requests order cancellation
- Shipment is cancelled by admin or system
- Delivery attempt fails and shipment is cancelled
- Shipping platform cancels the shipment
- Payment issues result in cancellation
Webhook Payload Structure
{
"event": "shipment.cancelled",
"timestamp": "2026-02-16T09:30:00.000Z",
"data": {
"shipmentId": "ship_abc123",
"trackingCode": "TRK123456789",
"platformConsignmentId": "CONS-789456",
"invoice": "INV-GROUP-og_abc123-1708426800000",
"status": "CANCELLED",
"platformType": "STEADFAST",
"shippedAt": "2026-02-15T11:00:00.000Z",
"deliveredAt": null,
"bulkShipmentId": "bulk_xyz789",
"attemptNumber": 1,
"orderGroupId": "og_abc123",
"orderGroupCode": "ORD-2026-001",
"deliveryCharge": 50,
"advancedPayment": 500,
"customer": {
"id": "cust_123",
"name": "John Doe",
"email": "john@example.com",
"phoneNumber": "+1234567890",
"shippingAddress": "123 Main St, City, Country"
},
"totalQuantity": 3,
"orderCount": 2,
"createdAt": "2026-02-15T11:00:00.000Z",
"updatedAt": "2026-02-16T09:30:00.000Z",
"platformResponse": {
"status": "cancelled",
"reason": "Customer requested cancellation",
"cancelled_at": "2026-02-16T09:30:00.000Z"
},
"errorMessage": "Customer requested cancellation",
"orders": [
{
"id": "item_1",
"productId": "prod_abc",
"productName": "Wireless Headphones",
"variant": "Black",
"quantity": 2,
"productImages": ["https://example.com/image1.jpg"],
"product": {
"id": "prod_abc",
"name": "Wireless Headphones",
"retailPrice": 2500,
"wholesalePrice": 2000,
"soldPrice": 2300,
"description": "Premium wireless headphones",
"images": ["https://example.com/image1.jpg"]
}
}
]
}
}Field Descriptions
Root Level
| Field | Type | Description |
|---|---|---|
event | string | Always "shipment.cancelled" for this event |
timestamp | string | ISO 8601 timestamp when the webhook was sent |
data | object | The shipment data object (see below) |
Data Object
| Field | Type | Required | Description |
|---|---|---|---|
shipmentId | string | Yes | Unique identifier for the shipment |
trackingCode | string | No | Tracking code from shipping platform |
platformConsignmentId | string | No | Consignment ID from shipping platform |
invoice | string | Yes | Invoice number for the shipment |
status | string | Yes | Will always be "CANCELLED" for this event |
platformType | string | No | Shipping platform used (STEADFAST, PATHAO) |
shippedAt | string | No | ISO 8601 timestamp when shipment was created |
deliveredAt | string | No | Will be null for cancelled shipments |
bulkShipmentId | string | No | ID if part of bulk shipment batch |
attemptNumber | number | Yes | Number of delivery attempts before cancellation |
orderGroupId | string | Yes | Associated order group ID |
orderGroupCode | string | No | Human-readable order code |
deliveryCharge | number | No | Delivery charge (may need refund) |
advancedPayment | number | No | Advance payment amount (may need refund) |
customer | object | Yes | Customer information (see below) |
totalQuantity | number | Yes | Total items that were to be shipped |
orderCount | number | Yes | Number of order line items |
createdAt | string | Yes | ISO 8601 timestamp of shipment creation |
updatedAt | string | Yes | ISO 8601 timestamp of cancellation |
platformResponse | object | No | Cancellation details from platform |
errorMessage | string | No | Reason for cancellation |
orders | array | Yes | Array of order items that were cancelled (see Order Item Object) |
Customer Object
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique customer identifier |
name | string | Yes | Customer's full name |
email | string | No | Customer's email address |
phoneNumber | string | No | Customer's phone number |
shippingAddress | string | No | Original shipping address |
Order Item Object
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique order item identifier |
productId | string | Yes | Product identifier |
productName | string | Yes | Name of the product |
variant | string | No | Product variant |
quantity | number | Yes | Quantity that was ordered |
productImages | array | No | Array of image URLs |
product | object | No | Full product details |
Enum Values
Status Values
For this event, status will always be:
CANCELLED- Shipment has been cancelled
Platform Types
STEADFAST- Steadfast courier servicePATHAO- Pathao courier service
Example Handler
Node.js / Express
app.post('/webhooks/shipments', async (req, res) => {
const { event, data } = req.body;
if (event === 'shipment.cancelled') {
const {
shipmentId,
customer,
orders,
errorMessage,
deliveryCharge,
advancedPayment,
orderGroupId,
} = data;
// Notify customer of cancellation
await sendCancellationNotification(customer.email, {
orderCode: data.orderGroupCode,
reason: errorMessage,
items: orders,
});
// Process refund if payment was made
if (advancedPayment > 0) {
await processRefund({
customerId: customer.id,
orderGroupId,
amount: advancedPayment + deliveryCharge,
reason: 'Shipment cancelled',
});
}
// Restore inventory
for (const order of orders) {
await restoreInventory({
productId: order.productId,
quantity: order.quantity,
reason: `Shipment ${shipmentId} cancelled`,
});
}
// Update order status
await updateOrderStatus(orderGroupId, 'CANCELLED');
// Log for analytics
await logCancellation({
shipmentId,
reason: errorMessage,
platformType: data.platformType,
daysInTransit: getDaysSince(data.shippedAt),
});
console.log(`Shipment ${shipmentId} cancelled: ${errorMessage}`);
}
res.status(200).json({ received: true });
});Python / Flask
@app.route('/webhooks/shipments', methods=['POST'])
def handle_shipment_webhook():
payload = request.get_json()
event = payload.get('event')
data = payload.get('data')
if event == 'shipment.cancelled':
shipment_id = data['shipmentId']
customer = data['customer']
orders = data['orders']
reason = data.get('errorMessage', 'Unknown reason')
# Send cancellation notification
send_cancellation_email(
customer['email'],
order_code=data['orderGroupCode'],
reason=reason,
items=orders
)
# Process refund if needed
if data.get('advancedPayment', 0) > 0:
process_refund(
customer_id=customer['id'],
amount=data['advancedPayment'] + data.get('deliveryCharge', 0),
reason='Shipment cancelled'
)
# Restore inventory
for order in orders:
restore_inventory(
product_id=order['productId'],
quantity=order['quantity']
)
# Update order status
update_order_status(data['orderGroupId'], 'CANCELLED')
print(f"Shipment {shipment_id} cancelled: {reason}")
return jsonify({'received': True}), 200Use Cases
1. Customer Communication
Notify customers and explain next steps:
async function notifyCustomer(shipmentData) {
const { customer, errorMessage, orders } = shipmentData;
await emailService.send({
to: customer.email,
subject: 'Order Cancellation Notice',
template: 'shipment-cancelled',
data: {
customerName: customer.name,
reason: errorMessage || 'Administrative cancellation',
items: orders.map((o) => ({
name: o.productName,
quantity: o.quantity,
})),
nextSteps: [
'Your payment will be refunded within 3-5 business days',
'You can place a new order anytime',
'Contact support if you have questions',
],
},
});
}2. Refund Processing
Handle automatic refunds:
async function processRefund(shipmentData) {
const { customer, advancedPayment, deliveryCharge, orderGroupId } =
shipmentData;
if (advancedPayment > 0) {
const refundAmount = advancedPayment + (deliveryCharge || 0);
const refund = await paymentGateway.createRefund({
customerId: customer.id,
orderId: orderGroupId,
amount: refundAmount,
reason: 'Shipment cancelled',
method: 'original_payment_method',
});
// Notify customer
await smsService.send({
to: customer.phoneNumber,
message: `Your refund of ${refundAmount} has been processed and will arrive in 3-5 business days.`,
});
return refund;
}
}3. Inventory Management
Restore cancelled items to inventory:
async function restoreInventory(shipmentData) {
const { orders, shipmentId } = shipmentData;
for (const order of orders) {
await inventory.adjust({
productId: order.productId,
variant: order.variant,
quantity: order.quantity,
operation: 'add',
reason: 'shipment_cancelled',
reference: shipmentId,
});
// Alert if product was out of stock
const stock = await inventory.getStock(order.productId);
if (stock.quantity <= stock.reorderPoint) {
await alertPurchasing({
productId: order.productId,
currentStock: stock.quantity,
reorderPoint: stock.reorderPoint,
});
}
}
}4. Cancellation Analytics
Track cancellation patterns:
async function analyzeCancellation(shipmentData) {
const {
shipmentId,
platformType,
errorMessage,
shippedAt,
customer,
orders,
} = shipmentData;
const daysInTransit = getDaysSince(shippedAt);
const orderValue = orders.reduce(
(sum, o) => sum + o.product.retailPrice * o.quantity,
0,
);
await analytics.track({
event: 'Shipment Cancelled',
properties: {
shipmentId,
platformType,
reason: errorMessage,
daysInTransit,
orderValue,
destination: customer.shippingAddress,
itemCount: orders.length,
},
});
// Flag high-value cancellations
if (orderValue > 10000) {
await alertManagement({
type: 'high_value_cancellation',
shipmentId,
orderValue,
reason: errorMessage,
});
}
}Best Practices
- Immediate Notification - Inform customers as soon as cancellation occurs
- Fast Refunds - Process refunds within 24 hours when applicable
- Restore Inventory - Return items to available stock immediately
- Track Reasons - Analyze cancellation reasons to improve service
- Offer Alternatives - Suggest rescheduling or alternative products
- Learn from Patterns - Monitor for recurring issues with specific routes or platforms
Common Cancellation Reasons
| Reason | Action Required |
|---|---|
| Customer requested | Process refund, confirm with customer |
| Delivery failed multiple times | Contact customer for address verification |
| Payment declined | Request payment update, hold order |
| Product out of stock | Refund and suggest alternatives |
| Address incorrect | Request correct address, offer reshipment |
| Platform error | Contact platform support, retry if possible |
Cancellation Flow
async function handleCancellationFlow(shipmentData) {
// 1. Update order status
await updateOrderStatus(shipmentData.orderGroupId, 'CANCELLED');
// 2. Notify customer
await notifyCustomer(shipmentData);
// 3. Process refund if needed
if (shipmentData.advancedPayment > 0) {
await processRefund(shipmentData);
}
// 4. Restore inventory
await restoreInventory(shipmentData);
// 5. Update analytics
await analyzeCancellation(shipmentData);
// 6. Offer recovery options
await offerRescheduling(shipmentData);
}Related Events
shipment.created- Initial shipment creationshipment.updated- Status updates
Testing
Test this webhook using the webhook testing tool in your dashboard:
- Navigate to Webhooks → Your Webhook → Test
- Select
shipment.cancelledevent - Send test payload with different
errorMessagevalues - Verify your handler:
- Sends cancellation notifications
- Processes refunds correctly
- Restores inventory
- Logs analytics
Need Help?
- Check the Getting Started Guide for setup instructions
- Review webhook security best practices
- Contact support if you encounter issues