Order Drafts
Order drafts are WhatsApp-parsed orders pending review before conversion to real client orders.
All routes are prefixed with /order-drafts.
GET /order-drafts
Get all pending order drafts.
Response
GET /order-drafts/{draft_id}
Get a specific order draft with all its entries.
PUT /order-drafts/{draft_id}
Update metadata of an order draft.
DELETE /order-drafts/{draft_id}
Delete an order draft and all its entries.
PUT /order-drafts/{draft_id}/entries/{entry_id}
Update a specific entry within a draft.
Request Body
POST /order-drafts/{draft_id}/recalculate_slip_numbers
Recalculate and reassign slip numbers for all entries in a draft.
POST /order-drafts/{draft_id}/convert
Convert a reviewed draft into actual client orders. Creates real client_order records and deletes the draft.
WhatsApp Webhook
POST /gupshup_incoming_webhook
Receives incoming WhatsApp messages from Gupshup.
Flow:
- Customer sends an order via WhatsApp
- Gupshup forwards the message to this endpoint
- Sender’s phone number is checked against
ALLOWED_PHONE_NUMBERS
- If allowed, message is sent to OpenAI for structured parsing
- An
OrderDraft is created with parsed entries
- A WhatsApp confirmation reply is sent back
- Staff review the draft at
/order-drafts in the frontend
- Once confirmed, draft is converted to real client orders
Only phone numbers listed in ALLOWED_PHONE_NUMBERS env var are processed. All others are silently ignored.
Khata Upload
Khata upload processes scanned/photographed ledger sheets using OCR.
POST /khata-upload
Upload a khata image/PDF and get back parsed entries (v1).
Request: multipart/form-data
POST /khata-upload-v2
Upload and process using the v2 parsing pipeline.
POST /khata-submit
Submit reviewed khata entries into the ledger system.
POST /khata/submit
Alternative submission endpoint (v2 flow).