Shiprocket Integration — Local Webhook Simulator
Real Shiprocket pushes tracking webhooks over hours or days, as a courier physically moves a package. That’s unworkable for local development, so mock-service reproduces the same call sequence — hitting the exact same receiver documented in the tracking webhook reference — on a fixed interval instead of real courier movement.
Trigger
mock-service’s shiprocket-assign-awb.service.ts creates one mock_shiprocket_webhook_event document immediately after a successful, non-blocked AssignAWB call (see the fulfillment API reference’s Step 2) — the earliest point the AWB code, courier name, and Shiprocket order/shipment IDs are all known together.
Schema — mock_shiprocket_webhook_event
| Field | Type | Notes |
|---|---|---|
_id |
string |
= Shiprocket’s order_id (the natural key) |
shiprocket_shipment_id |
string |
|
awb_code |
string |
Converted to a bare JSON number (Number(awb_code)) when building each webhook payload |
courier_name |
string |
|
status_index |
number |
Index into the status sequence below — the last step successfully dispatched |
pending |
boolean |
false once DELIVERED is reached — the scheduler’s query then naturally excludes it |
scans |
{date, activity, location}[] |
Newest-first, mirrors the real payload’s ordering |
last_call_at / last_call_status / last_call_error / call_count |
— | Updated on every dispatch attempt, success or failure |
Deviation from the global 5-field audit rule: no tenant_id — mock-service has no auth/tenant context anywhere else in the service.
Scheduler — @Interval(30000)
dispatchPendingEvents() runs every 30 seconds in the real, running code, pulls every record with pending: true, and advances each one exactly one step per tick:
| Index | current_status |
Dispatched? |
|---|---|---|
| 0 | AWB ASSIGNED |
No — seed state at record creation, no webhook call |
| 1 | PICKED UP |
Yes |
| 2 | IN TRANSIT |
Yes |
| 3 | OUT FOR DELIVERY |
Yes |
| 4 | DELIVERED |
Yes — sets pending: false |
A full order reaches DELIVERED roughly 2 minutes after AWB assignment — not the ~20 seconds some of mock-service’s own design docs describe; this page follows shipment-service’s “Implementation Notes” in treating the running @Interval(30000) as authoritative over the stale @Interval(5000) the original design doc specified. Only DELIVERED (current_status_id: 7) is verified against the real Shiprocket sample in the tracking webhook reference — the intermediate statuses are mock-only placeholders, not real Shiprocket codes.
A failed dispatch (non-2xx, timeout, network error) does not advance status_index — the same step retries on the next tick, and last_call_*/call_count are updated regardless so a stuck record stays visible in Mongo.
Payload construction
{
"awb": 59629792084,
"order_id": "<shiprocketOrderId>",
"current_status": "OUT FOR DELIVERY",
"current_status_id": 17,
"current_timestamp": "2026-09-13 10:00:05",
"etd": "2026-09-13 10:00:05",
"shipment_status": "OUT FOR DELIVERY",
"shipment_status_id": 17,
"channel_order_id": "",
"channel": "",
"courier_name": "Delhivery",
"scans": [
{ "date": "2026-09-13 10:00:05", "activity": "SHIPMENT OUT FOR DELIVERY", "location": "Mumbai Local Delivery Center" }
]
}
awbis emitted as a bare JSON number (Number(record.awb_code)) — matching the real sample and thejson.Numberfix on the receiving side.- Timestamps use
"YYYY-MM-DD HH:mm:ss", matching Shiprocket’s real format. scans[]is prepended newest-first, matching both the real payload and the mock’s stored order.
Call target
POST http://cdn-edge:3128/shipment/webhook/shiprocket
X-Api-Key: <MOCK_SHIPROCKET_WEBHOOK_TOKEN>
This routes through the same Squid → nginx-api-router → shipment-service path a real external Shiprocket webhook call would take, rather than calling shipment-service directly — so the simulator exercises the full receiving path, not just the handler function. Built on node-lang-core-lib’s createHttpClient, never a hand-rolled HTTP client.
One manual setup step
MOCK_SHIPROCKET_WEBHOOK_TOKEN must be set to the exact same value as shipment-service’s real SHIPROCKET_WEBHOOK_TOKEN — this is a manual .env step on both sides (not something read or verified here, per the project’s secrets-handling rule), documented in mock-service’s own “still manual” notes.
Related Documents
- Hub — Shiprocket Integration
- Tracking Webhook Reference — previous: the real receiver this simulator calls
- Fulfillment API Reference — where the simulated sequence starts, right after
AssignAWB - mock-service
- ADR-00023 — Internal Mock Service vs. Direct Live API for Non-Production Shiprocket Calls