API overview
:::info Implemented by cmd/api, cmd/mcp and cmd/a2a
cmd/api serves every REST route below (internal/adapters/inbound/http) on HTTP_ADDR (default :8080). The contracts are apis/openapi.yaml and apis/asyncapi.yaml, pinned by ADR 0001, ADR 0002 and ADR 0004. The router registers exactly the four API routes plus /healthz and /readyz; the two probe routes are not in openapi.yaml.
:::
| Interface | Source of truth | Notes |
|---|---|---|
| REST | apis/openapi.yaml (OpenAPI 3.0.3, version 0.1.0) | The pages under REST in the sidebar are generated from the spec with npm run gen-api-docs; do not edit them by hand. Server named in the spec: http://localhost:8080. Through Kong (port 8000) the API is at /api/shipping-and-tracking with the prefix stripped (helm-values/shipping-and-tracking.yaml in warehouse-infra). |
| Events | apis/asyncapi.yaml (AsyncAPI 3.0.0, version 1.0.0) | Thirteen published events on retailnetwork.shipping-and-tracking.events, fourteen consumed types from five topics. Summarised on the event catalogue; every field on Domain events. |
| MCP | ADR 0006, internal/adapters/inbound/mcp | cmd/mcp serves Streamable HTTP on /mcp and / (port 8090; through Kong /api/mcp/shipping-and-tracking). One read-only tool, get_journey (trackingNumber), no write tool. No auth, by fleet decision. See MCP tools. |
| A2A | ADR 0009, internal/adapters/inbound/a2a | cmd/a2a serves JSON-RPC 2.0 on / and /a2a (port 8093; through Kong /api/a2a/shipping-and-tracking), the Agent Card at /.well-known/agent-card.json. One read-only skill, get_journey (trackingNumber), no write skill. The request is a message whose first part carries {"skill":"get_journey","arguments":{"trackingNumber":"..."}}; unknown fields are refused. Domain rejections (not-found, validation-failed, internal-error) are answered inside the reply message as RFC 9457-shaped problems, never as JSON-RPC errors. Message-only agent, no streaming. No auth, by fleet decision. |
Endpoints
| Tag | Endpoint | Operation id | Success |
|---|---|---|---|
| Labels | POST /labels | issueLabel | 201, the label metadata (labelRef, trackingNumber, carrier, ...), never the address. Reads the ship-to from customer-ordering first |
| Labels | POST /return-labels | issueReturnLabel | 201, the reverse label of one package of a customer return (ReturnLabel: no poNumber, no assignmentId, purpose: RETURN, the returnAuthorizationId). The return destination is named by exactly one of destinationNodeId (this context derives the label's prefix from its own node view, ADR 0018) and the deprecated destinationPostalPrefix; a node without a usable prefix here is 409 destination-prefix-unavailable |
| Labels | POST /labels/{labelRef}/voids | voidLabel | 200, the label (VOIDED); a label already voided is returned unchanged |
| Journeys | GET /journeys/{trackingNumber} | getJourney | 200, the journey with every stored scan; 404 not-found |
| Journeys | POST /journeys/{trackingNumber}/scans | recordScan | 200, the journey after the scan |
| Health | GET /healthz, GET /readyz | none (not in the spec) | 200; /readyz is 503 while Postgres or Kafka is down or the process drains |
| reports | GET /reports/package-touches?from=&to= | getPackageTouchesReport | 200, per UTC day and tier: delivered packages and touches per package (mean, p50, p90). Served by cmd/st-reports on :8092 (ADR 0012) |
| reports | GET /reports/delivery-outcomes?from=&to= | getDeliveryOutcomesReport | 200, per UTC day: delivered, first-attempt delivered, returned, lost and the rates; 400 invalid-report-range |
| reports | GET /reports/freshness | getReportFreshness | 200, asOf and lagSeconds of the analytics projection (both null before the first event) |
Every POST requires an Idempotency-Key header.
Conventions in the contract
- Idempotency-Key. Required on all three POSTs (
internal/adapters/inbound/http/idempotency.go): 1-128 printable ASCII characters, global across routes. A repeat with the same key, method, path and body replays the first answer for 24 hours withIdempotency-Replayed: truewhen that answer is final for the request (ADR 0020): a success; the FINAL refusalsnot-found,label-already-issued,void-after-handover,journey-closedandduplicate-scan; and the OUTCOME refusalsscan-out-of-orderandillegal-transition, whose scan is stored with the answer. The same key with a different method, path or body, while an answer is stored, is409 idempotency-key-reused; a missing key is400 idempotency-key-requiredand a malformed one400 idempotency-key-invalid. A 5xx is never stored, and neither is a RETRYABLE refusal, one that follows state which can change:validation-failed,address-suspect,pickup-point-unavailable,destination-prefix-unavailable,tracking-number-takenandconcurrent-update. After one of those the key is free again, the retry with the same key is executed, and another body under the key is a new request. - Errors are RFC 9457
application/problem+json;typeis a slug, the model'sErrname in kebab-case:validation-failed,address-suspectandpickup-point-unavailable(422),idempotency-key-requiredandidempotency-key-invalid(400),idempotency-key-reused(409),not-found(404),label-already-issued,destination-prefix-unavailable,tracking-number-taken,void-after-handover,duplicate-scan,scan-out-of-order,journey-closed,illegal-transition,concurrent-update(409),ship-to-unavailable(503) andinternal-error(500). Method and route misses aremethod-not-allowed(405) andnot-found(404). Causes and remedies are on Troubleshooting. - Scans that are stored but not applied.
scan-out-of-orderandillegal-transitionanswer 409 and still keep the scan withapplied=false;duplicate-scanstores nothing. - Request bodies reject unknown fields (
additionalProperties: false); timestamps are RFC 3339 UTC. - No ship-to address anywhere. No schema of either contract carries an address field (
TestContractsCarryNoShipToField).LabelIssuedcarries only an opaquestopKeyand a postal prefix. - Events are CloudEvents 1.0, structured mode, type
com.retailnetwork.logistics.shipping-and-tracking.<label|journey>.<EventName>, one transactional outbox, Kafka key = the aggregate id. - Auth: none. The fleet reverted REST, MCP and A2A auth on 2026-09-11, and
TestNoAuthMiddlewareReintroducedfails CI if auth middleware returns.
Code versus spec
GET /healthzandGET /readyzare registered by the router (internal/adapters/inbound/http/server.go) but absent fromapis/openapi.yaml.- A key reused with a different request is
409 idempotency-key-reused(ADR 0010; it was422 validation-failedbefore).