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/v1/company/products?userId=1" \
-H "Content-Type: application/json" \
-d '{
"name": "Eco Polo Shirt",
"code": "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/v1/traceability?userId=1" \
-H "Content-Type: application/json" \
-d '{
"product_id": "5",
"batch_number": "POLO-BATCH-001",
"origin": "Mumbai, India",
"destination": "Porto, Portugal"
}'

3. Bulk Insert Processing Stages

Shell
curl -X POST http://localhost:8080/api/v1/product/traceability/1/stages/bulk \
-H "Content-Type: application/json" \
-d '{
"stages": [
{ "sequence_order": 1, "stage_name": "Raw Cotton Farming",
"supplier_id": 5, "distance_km": 0, "co2_emissions": 0 },
{ "sequence_order": 2, "stage_name": "Spinning",
"supplier_id": 5, "transport_mode": "ROAD", "distance_km": 320, "co2_emissions": 0.04 },
{ "sequence_order": 3, "stage_name": "Dyeing & Finishing",
"supplier_id": 8, "transport_mode": "SEA", "distance_km": 2100, "co2_emissions": 0.18 },
{ "sequence_order": 4, "stage_name": "Cut & Sew",
"supplier_id": 12, "transport_mode": "SEA", "distance_km": 9200, "co2_emissions": 0.31 }
]
}'

After this call, ProductTraceability is automatically updated:

  • total_distance_km = 11 620
  • total_co2_per_kg = 0.53