Traceability API

Reference for TraceabilityRecord and ProcessingStage endpoints with automatic totals recalculation.

Traceability Records

MethodPathDescription
GET/api/v1/traceabilityList traceability records (paginated)
GET/api/v1/traceability/{id}Get a traceability record by ID
GET/api/v1/traceability/product/{productId}Find records by product ID
GET/api/v1/traceability/batch/{batchNumber}Find records by batch number
POST/api/v1/traceabilityCreate a traceability record
PATCH/api/v1/traceability/{id}Update a traceability record
DELETE/api/v1/traceability/{id}Delete a traceability record

GET /api/v1/traceability

Query Parameters

ParameterTypeDefaultDescription
pageinteger0Zero-based page index
sizeinteger20Items per page
productIdstringFilter by product ID
batchNumberstringFilter by batch number
Shell
curl "http://localhost:8080/api/v1/traceability?productId=3&page=0&size=10"

POST /api/v1/traceability

Request Body

FieldTypeRequiredDescription
product_idstringAssociated product ID
batch_numberstringBatch number
originstringOrigin location
destinationstringDestination location
supplier_idintegerFK to Supplier.id
processing_facilitystringName of processing facility
certificationsstringCertifications held
is_compliantbooleanCompliance flag
notesstringNotes
metadataobjectArbitrary JSON key-value pairs
Shell
curl -X POST "http://localhost:8080/api/v1/traceability?userId=1" \
-H "Content-Type: application/json" \
-d '{
"product_id": "3",
"batch_number": "BATCH-2025-001",
"origin": "Mumbai, India",
"destination": "Milano, Italy",
"supplier_id": 1,
"is_compliant": true
}'
JavaScript
const resp = await fetch('/api/v1/traceability?userId=1', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
product_id: '3',
batch_number: 'BATCH-2025-001',
origin: 'Mumbai, India',
destination: 'Milano, Italy',
supplier_id: 1,
is_compliant: true
})
});

Processing Stages

Processing stages are managed under the ProductTraceability aggregate. The base path is /api/v1/product/traceability.

MethodPathDescription
POST/api/v1/product/traceability/{traceability_id}/stagesCreate a processing stage
PATCH/api/v1/product/traceability/stages/{id}Update a processing stage
GET/api/v1/product/traceability/{traceability_id}/stagesList stages for a traceability record
DELETE/api/v1/product/traceability/stages/{id}Delete a processing stage
POST/api/v1/product/traceability/{traceability_id}/stages/bulkBulk upsert stages

POST /api/v1/product/traceability/{traceability_id}/stages

Request Body

FieldTypeRequiredDescription
sequence_orderintegerPosition in the processing chain
stage_namestringe.g. Spinning, Dyeing, Cutting
company_typestringType of company performing the stage
supplier_idintegerSupplier performing this stage
company_idintegerCompany performing this stage
internal_processbooleanWhether this is an internal process
transport_modestringTransport mode to this stage
starts_from_companybooleanWhether transport starts from company
distance_kmnumberTransport distance from previous stage
co2_emissionsnumberCO₂ emissions for this stage
certifications_snapshotstringCertifications at this stage
Shell
curl -X POST http://localhost:8080/api/v1/product/traceability/10/stages \
-H "Content-Type: application/json" \
-d '{
"sequence_order": 1,
"stage_name": "Spinning",
"supplier_id": 5,
"distance_km": 0,
"co2_emissions": 0
}'

POST /api/v1/product/traceability/{traceability_id}/stages/bulk

Creates or updates multiple stages in one request. After bulk insert, the parent ProductTraceability.total_distance_km and total_co2_per_kg are automatically recalculated.

JSON
{
"stages": [
{
"sequence_order": 1,
"stage_name": "Spinning",
"supplier_id": 5,
"distance_km": 0,
"co2_emissions": 0
},
{
"sequence_order": 2,
"stage_name": "Dyeing",
"supplier_id": 8,
"transport_mode": "ROAD",
"distance_km": 2200,
"co2_emissions": 0.18
},
{
"sequence_order": 3,
"stage_name": "Cutting",
"supplier_id": 12,
"transport_mode": "SEA",
"distance_km": 8500,
"co2_emissions": 0.42
}
]
}

Response 200 OK

JSON
{
"created": 2,
"updated": 1,
"failed": 0,
"errors": []
}
Note

After any stage is created, updated, or deleted, the parent ProductTraceability record's total_distance_km and total_co2_per_kg fields are automatically recalculated by summing all child stages.