Overview
Provides a lightweight endpoint for polling order status updates. This endpoint is optimized for frequent polling with minimal data transfer using lean queries.
Use this endpoint to:
Track order progress in real-time
Update UI without fetching full order details
Monitor multiple orders efficiently
Build live order tracking dashboards
This endpoint uses MongoDB lean queries for optimal performance and can be called frequently without significant database load.
Authentication
Requires authentication with JWT token. Available to all authenticated users.
Endpoint
GET /api/orders/:id/poll-status
Path parameters
The unique order ID (MongoDB ObjectId)
Response
Indicates if the request was successful
Order status information Human-readable order number
Current order status: placed, accepted, processing, ready, picked_up, or cancelled
Payment status: pending, success, or failed
Total order amount in rupees
Whether customer confirmed commitment
ISO timestamp when commitment confirmation expires
ISO timestamp when order was marked as ready
ISO timestamp when ready order expires
Whether pickup OTP was verified
ISO timestamp when order was cancelled
Reason for cancellation if applicable
ISO timestamp of last update
Polling recommendations
Polling intervals
Active orders (placed, accepted, processing): Poll every 5-10 seconds
Ready orders : Poll every 3-5 seconds for OTP verification
Completed orders (picked_up, cancelled): Stop polling
Efficient polling pattern
let pollInterval ;
let lastStatus ;
async function pollOrderStatus ( orderId ) {
const response = await fetch (
`https://api.campusbite.com/api/orders/ ${ orderId } /poll-status` ,
{
headers: { 'Authorization' : `Bearer ${ token } ` }
}
);
const data = await response . json ();
const order = data . data ;
// Only update UI if status changed
if ( order . orderStatus !== lastStatus ) {
updateUI ( order );
lastStatus = order . orderStatus ;
}
// Stop polling for terminal states
if ( order . orderStatus === 'picked_up' || order . orderStatus === 'cancelled' ) {
clearInterval ( pollInterval );
}
}
// Start polling
pollInterval = setInterval (() => pollOrderStatus ( orderId ), 5000 );
Use WebSocket connections for production applications to reduce server load. Polling should be limited to 1 request per 3-5 seconds maximum.
Example request
curl -X GET https://api.campusbite.com/api/orders/65f7a8b9c1234567890abcde/poll-status \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
Example response
{
"success" : true ,
"data" : {
"id" : "65f7a8b9c1234567890abcde" ,
"orderNumber" : "ORD-20240318-001" ,
"orderStatus" : "processing" ,
"paymentStatus" : "success" ,
"totalAmount" : 249.50 ,
"isCommitmentConfirmed" : true ,
"commitmentDeadlineAt" : null ,
"readyAt" : null ,
"readyExpiresAt" : null ,
"isOtpVerified" : false ,
"cancelledAt" : null ,
"cancellationReason" : null ,
"updatedAt" : "2024-03-18T14:40:00.000Z"
}
}
Error responses
Show 404 - Order not found
{
"success" : false ,
"message" : "Order not found."
}
Show 403 - Not authorized
{
"success" : false ,
"message" : "You are not authorized to view this order."
}
Use cases
For customers
Track order preparation progress
Receive real-time updates when order is ready
Monitor commitment deadline countdown
Check if payment was verified
For store employees
Monitor if customer confirmed commitment
Check payment status updates
Track OTP verification status
Build live order dashboard
Status change detection
To detect status changes efficiently:
let lastUpdatedAt ;
async function checkForUpdates ( orderId ) {
const response = await fetch (
`https://api.campusbite.com/api/orders/ ${ orderId } /poll-status` ,
{ headers: { 'Authorization' : `Bearer ${ token } ` } }
);
const { data } = await response . json ();
if ( data . updatedAt !== lastUpdatedAt ) {
console . log ( 'Order updated:' , data . orderStatus );
lastUpdatedAt = data . updatedAt ;
// Fetch full order details if needed
if ( needsFullDetails ( data )) {
fetchFullOrderDetails ( orderId );
}
}
}
Response time : < 50ms (lean query)
Payload size : ~200-300 bytes
Database load : Minimal (indexed fields only)
Recommended poll rate : 3-10 seconds
This endpoint automatically runs order timeout sweeps to ensure cancelled orders due to timeouts are reflected immediately.