Create, list, track, and poll deliveries.
flasho.deliveries
flasho.deliveries
create()
Book a delivery. Works for on-demand, scheduled, and cash-on-delivery orders.
On-demand
const { delivery } = await flasho.deliveries.create({
customerName: 'Ahmed Ali',
customerNumber: '99887766',
pickupLatitude: 29.3764,
pickupLongitude: 47.9785,
deliveryLatitude: 29.3117,
deliveryLongitude: 48.0034,
});
console.log(delivery.orderNumber); // FLH4001
console.log(delivery.status); // PENDING
console.log(delivery.estimatedPrice); // "1.250"Cash-on-delivery
const { delivery } = await flasho.deliveries.create({
customerName: 'Sara Mohammed',
customerNumber: '66554433',
pickupLatitude: 29.3764,
pickupLongitude: 47.9785,
deliveryLatitude: 29.3117,
deliveryLongitude: 48.0034,
collectCash: true,
totalAmount: '15.750', // amount driver collects in KWD
specialNotes: 'Collect exact amount only',
});Scheduled delivery
// Always check availability first
const { scheduledDelivery } = await flasho.account.getScheduledDeliverySettings();
if (!scheduledDelivery.available) throw new Error('Scheduled delivery not enabled');
const { delivery } = await flasho.deliveries.create({
customerName: 'Ahmed Ali',
customerNumber: '99887766',
pickupLatitude: 29.3764,
pickupLongitude: 47.9785,
deliveryLatitude: 29.3117,
deliveryLongitude: 48.0034,
isScheduled: true,
scheduledDeliveryAt: '2026-12-01T10:00:00.000Z', // ISO 8601 UTC
specialNotes: 'Ring doorbell',
});⚠️ Scheduled time constraints
scheduledDeliveryAt must be at least 30 minutes from now and no more than 14 days ahead.
Full request reference
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
customerName | string | ✓ | — | Recipient full name |
customerNumber | string | ✓ | — | Recipient phone number |
pickupLatitude | number | ✓ | — | Pickup GPS latitude |
pickupLongitude | number | ✓ | — | Pickup GPS longitude |
deliveryLatitude | number | ✓ | — | Drop-off GPS latitude |
deliveryLongitude | number | ✓ | — | Drop-off GPS longitude |
alternateCustomerNumber | string | — | — | Secondary phone |
additionalAddressDetail | string | — | — | Apartment / floor |
deliveryAddress | string[] | — | Auto | Address parts array |
pickupName | string | — | — | Override pickup contact name |
pickupNumber | string | — | — | Override pickup contact phone |
branchId | string | — | — | Optional branch reference |
collectCash | boolean | — | false | Enable COD |
totalAmount | string | — | "0.000" | COD amount in KWD |
specialNotes | string | — | — | Driver instructions |
vehicleType | "bike"|"car"|"van" | — | "bike" | Vehicle type |
isScheduled | boolean | — | false | Scheduled delivery |
scheduledDeliveryAt | string | ✓ if scheduled | — | ISO 8601 UTC datetime |
list()
Retrieve deliveries newest-first. Optionally filter by status or limit results.
// Latest 20
const { deliveries } = await flasho.deliveries.list({ limit: 20 });
// Active deliveries only
const { deliveries } = await flasho.deliveries.list({ status: 'ENROUTE' });
// All pending
const { deliveries } = await flasho.deliveries.list({ status: 'PENDING' });| Parameter | Type | Default | Description |
|---|---|---|---|
status | DeliveryStatus | — | Filter by status |
limit | number | 50 | Max results (1–100) |
get()
Fetch a single delivery by its ID. Use this to check status and driver assignment.
const { delivery } = await flasho.deliveries.get('clx...');
console.log(delivery.status); // ENROUTE
console.log(delivery.driverName); // Mohammed
console.log(delivery.driverPhone); // 99112233
console.log(delivery.statusHistory);
// [{ status: 'PENDING', timestamp: '...' }, { status: 'ACCEPTED', timestamp: '...' }]poll()
Poll a delivery until it reaches a terminal state. Handles the interval/timeout loop for you.
const finalDelivery = await flasho.deliveries.poll(delivery.id, {
intervalMs: 5000, // poll every 5 seconds (default)
timeoutMs: 900_000, // give up after 15 minutes (default)
onUpdate: (d) => {
console.log('Status →', d.status);
if (d.driverName) {
console.log('Driver:', d.driverName, d.driverPhone);
}
},
});
if (finalDelivery.status === 'DELIVERED') {
console.log('Delivery complete!');
} else {
console.log('Delivery ended with:', finalDelivery.status);
}| Option | Type | Default | Description |
|---|---|---|---|
intervalMs | number | 5000 | Milliseconds between polls |
timeoutMs | number | 900000 | Max wait time before throwing |
onUpdate | function | — | Called each time the status changes |
📝 Terminal states
poll() resolves when the delivery reaches one of: DELIVERED, CANCELLED, REJECTED, or FAILED. It throws a plain Error if timeoutMs is exceeded.
Order statuses
| Status | Description |
|---|---|
PENDING | Booked, awaiting dispatch |
REQUESTED | Driver request sent |
ACCEPTED | Driver accepted |
INPROGRESS | Driver heading to pickup |
PICKEDUP | Order collected from pickup |
ENROUTE | Driver heading to customer |
DELIVERED | Complete ✓ |
CANCELLED | Cancelled |
REJECTED | No driver available |
FAILED | Delivery failed |