Skip to content

Update Batch Stage

Advances a BatchToken to the next custody stage. Stages must advance sequentially — no skipping. Writes to both TraceLog.sol on Mantle and Hedera HCS.

PATCH /batch/{batch_id}/stage

Auth: COOPERATIVE or AGENT token (role restrictions apply per stage).

Stage being setRequired roleNotes
GRADEDCOOPERATIVE (quality officer)Must include grade data
MILLEDCOOPERATIVE (mill operator)
WAREHOUSEDCOOPERATIVE (warehouse manager)Must include warehouse reference
COMMITTEDAuto-triggered by PurchaseOrder confirmationDo not call directly
EXPORTEDCOOPERATIVE (exporter)Must include UCDA export reference
SETTLEDAuto-triggered by LendingVault on buyer paymentDo not call directly
Terminal window
curl -X PATCH https://api.asilichain.xyz/batch/BATCH-2026-004821/stage \
-H "Authorization: Bearer {cooperative_token}" \
-H "Content-Type: application/json" \
-d '{
"new_stage": "GRADED",
"evidence": {
"grade": "screen18",
"moisture_pct": 11.2,
"screen_size": 18,
"defect_count": 2,
"cupping_score": 84.5
},
"evidence_photo_base64": "data:image/jpeg;base64,...",
"cooperative_id": "COOP-MBALE-001"
}'
FieldTypeRequiredDescription
new_stagestringYesOne of: GRADED, MILLED, WAREHOUSED, EXPORTED
evidenceobjectYesStage-specific evidence data (see below)
evidence_photo_base64stringNoPhoto of grade certificate, weight slip, etc. Pinned to IPFS.
cooperative_idstringYesMust match token’s cooperative

GRADED:

{
"grade": "screen18",
"moisture_pct": 11.2,
"screen_size": 18,
"defect_count": 2,
"cupping_score": 84.5
}

WAREHOUSED:

{
"warehouse_id": "UWRSA-WH-MBALE-001",
"lot_number": "LOT-2026-0089",
"position": "Stack A, Row 3, Bag 12-67"
}

EXPORTED:

{
"ucda_export_permit": "UCDA-EXP-2026-04821",
"destination_country": "DE",
"vessel_name": "MSC Eleonora",
"bill_of_lading": "MSCUG123456"
}
{
"batch_id": "BATCH-2026-004821",
"previous_stage": "DELIVERED",
"new_stage": "GRADED",
"mantle_tx_hash": "0xbcd123...",
"hedera_sequence_number": "847291",
"evidence_ipfs_cid": "bafybeig...",
"dds_eligible": true,
"timestamp": "2026-04-17T14:00:00Z"
}
FieldDescription
mantle_tx_hashTraceLog.updateStage() transaction on Mantle
hedera_sequence_numberHCS message sequence number for audit trail
evidence_ipfs_cidIPFS CID of evidence JSON + photo (if provided)
dds_eligibletrue if batch is now GRADED or above
CodeTrigger
STAGE_OUT_OF_ORDERAttempted to skip a stage or go backward
BATCH_NOT_FOUNDbatch_id not recognised
INVALID_GRADEGrade not in accepted set
INSUFFICIENT_PERMISSIONSAgent token attempting cooperative-level stage