Traceability Tracking

Build a full multi-stage supply chain traceability chain for a company product.

1. Create a Company Product

Shell
curl -X POST http://localhost:8080/api/company-products \
-H "Content-Type: application/json" \
-H "X-User-Id: 1" -H "X-API-Key: dev-key" \
-d '{
"name": "Eco Polo Shirt",
"sku": "POLO-ECO-001",
"unit_of_measure": "PIECES",
"product_origin_country": "PT",
"raw_material_origin_country": "IN"
}'

2. Create a Traceability Record

Shell
curl -X POST http://localhost:8080/api/traceability \
-H "Content-Type: application/json" \
-d '{ "company_product_id": 5, "status": "DRAFT" }'

3. Bulk Insert Processing Stages

Shell
curl -X POST http://localhost:8080/api/processing-stages/bulk \
-H "Content-Type: application/json" \
-d '{
"stages": [
{ "traceability_id": 1, "stage_name": "Raw Cotton Farming",
"stage_order": 1, "country_code": "IN", "distance_km": 0 },
{ "traceability_id": 1, "stage_name": "Spinning",
"stage_order": 2, "country_code": "IN", "distance_km": 320, "co2_kg": 0.04 },
{ "traceability_id": 1, "stage_name": "Dyeing & Finishing",
"stage_order": 3, "country_code": "BD", "distance_km": 2100, "co2_kg": 0.18 },
{ "traceability_id": 1, "stage_name": "Cut & Sew",
"stage_order": 4, "country_code": "PT", "distance_km": 9200, "co2_kg": 0.31 }
]
}'

After this call, ProductTraceability is automatically updated:

  • total_distance_km = 11 620
  • total_co2_kg = 0.53