Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Shipment Events

Shipment events are triggered when shipments are created, updated, change status, have items assigned, or are deleted.

Copy these interfaces to type your webhook handlers:

/** Base event properties included in all webhook events */
interface BaseEvent {
/** Unique event identifier (UUID) */
id: string;
/** Event type */
kind: string;
/** ISO 8601 timestamp */
time: string;
/** Transaction identifier for grouping related events */
transactionId: string;
}
/** Shipment status values */
type ShipmentStatus =
| "pending"
| "picking"
| "packed"
| "in_transit"
| "delivered"
| "cancelled";

Triggered when a new shipment is created.

{
"id": "evt_abc123",
"kind": "shipment.created",
"time": "2024-01-15T10:30:00Z",
"transactionId": "txn_xyz789",
"shipmentId": "shp_456",
"shipmentShortId": "SHP-001"
}

Triggered when shipment details are updated.

{
"id": "evt_abc123",
"kind": "shipment.updated",
"time": "2024-01-15T10:30:00Z",
"transactionId": "txn_xyz789",
"shipmentId": "shp_456",
"shipmentShortId": "SHP-001"
}

Triggered when a shipment’s status is updated.

{
"id": "evt_abc123",
"kind": "shipment.status.changed",
"time": "2024-01-15T10:30:00Z",
"transactionId": "txn_xyz789",
"shipmentId": "shp_456",
"shipmentShortId": "SHP-001",
"previousShipmentStatus": "pending",
"currentShipmentStatus": "in_transit"
}
StatusDescription
pendingShipment created
pickingItems being picked
packedShipment packed
in_transitShipment in transit
deliveredShipment delivered
cancelledShipment cancelled

Triggered when items are assigned to a shipment for a specific order.

{
"id": "evt_abc123",
"kind": "shipment.items.assigned",
"time": "2024-01-15T10:30:00Z",
"transactionId": "txn_xyz789",
"shipmentId": "shp_456",
"shipmentOrderId": "ord_789"
}

Triggered when a shipment is deleted.

{
"id": "evt_abc123",
"kind": "shipment.deleted",
"time": "2024-01-15T10:30:00Z",
"transactionId": "txn_xyz789",
"shipmentId": "shp_456"
}

Union type for handling any shipment event:

type ShipmentEvent =
| ShipmentCreatedEvent
| ShipmentUpdatedEvent
| ShipmentStatusChangedEvent
| ShipmentItemsAssignedEvent
| ShipmentDeletedEvent;
// Type guard for shipment events
function isShipmentEvent(event: BaseEvent): event is ShipmentEvent {
return event.kind.startsWith("shipment.");
}
// Example webhook handler
async function handleShipmentWebhook(event: ShipmentEvent) {
switch (event.kind) {
case "shipment.created":
console.log(`New shipment created: ${event.shipmentShortId}`);
break;
case "shipment.updated":
console.log(`Shipment ${event.shipmentShortId} was updated`);
break;
case "shipment.status.changed":
console.log(
`Shipment ${event.shipmentShortId} changed from ${event.previousShipmentStatus} to ${event.currentShipmentStatus}`
);
if (event.currentShipmentStatus === "in_transit") {
// Send tracking notification to customer
} else if (event.currentShipmentStatus === "delivered") {
// Update order fulfillment status
}
break;
case "shipment.items.assigned":
console.log(
`Items assigned to shipment ${event.shipmentId} for order ${event.shipmentOrderId}`
);
break;
case "shipment.deleted":
console.log(`Shipment ${event.shipmentId} was deleted`);
break;
}
}