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
[
{
"id": 1,
"created_at": "2025-01-15T10:30:00",
"phone_number": "917595903437",
"raw_message": "2 rings 5g each for Priya",
"entries": [
{
"id": 1,
"item_name": "Ring",
"weight": 5.0,
"quantity": 2,
"client_name": "Priya"
}
]
}
]
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
{
"item_name": "Ring",
"weight": 5.2,
"quantity": 2,
"client_id": 1,
"slip_number": "SL-042"
}
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
| Field | Type | Description |
|---|
file | file | Image or PDF of the khata page |
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).