Skip to main content

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. :::

InterfaceSource of truthNotes
RESTapis/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).
Eventsapis/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.
MCPADR 0006, internal/adapters/inbound/mcpcmd/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.
A2AADR 0009, internal/adapters/inbound/a2acmd/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​

TagEndpointOperation idSuccess
LabelsPOST /labelsissueLabel201, the label metadata (labelRef, trackingNumber, carrier, ...), never the address. Reads the ship-to from customer-ordering first
LabelsPOST /return-labelsissueReturnLabel201, 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
LabelsPOST /labels/{labelRef}/voidsvoidLabel200, the label (VOIDED); a label already voided is returned unchanged
JourneysGET /journeys/{trackingNumber}getJourney200, the journey with every stored scan; 404 not-found
JourneysPOST /journeys/{trackingNumber}/scansrecordScan200, the journey after the scan
HealthGET /healthz, GET /readyznone (not in the spec)200; /readyz is 503 while Postgres or Kafka is down or the process drains
reportsGET /reports/package-touches?from=&to=getPackageTouchesReport200, per UTC day and tier: delivered packages and touches per package (mean, p50, p90). Served by cmd/st-reports on :8092 (ADR 0012)
reportsGET /reports/delivery-outcomes?from=&to=getDeliveryOutcomesReport200, per UTC day: delivered, first-attempt delivered, returned, lost and the rates; 400 invalid-report-range
reportsGET /reports/freshnessgetReportFreshness200, 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 with Idempotency-Replayed: true when that answer is final for the request (ADR 0020): a success; the FINAL refusals not-found, label-already-issued, void-after-handover, journey-closed and duplicate-scan; and the OUTCOME refusals scan-out-of-order and illegal-transition, whose scan is stored with the answer. The same key with a different method, path or body, while an answer is stored, is 409 idempotency-key-reused; a missing key is 400 idempotency-key-required and a malformed one 400 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-taken and concurrent-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; type is a slug, the model's Err name in kebab-case: validation-failed, address-suspect and pickup-point-unavailable (422), idempotency-key-required and idempotency-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) and internal-error (500). Method and route misses are method-not-allowed (405) and not-found (404). Causes and remedies are on Troubleshooting.
  • Scans that are stored but not applied. scan-out-of-order and illegal-transition answer 409 and still keep the scan with applied=false; duplicate-scan stores 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). LabelIssued carries only an opaque stopKey and 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 TestNoAuthMiddlewareReintroduced fails CI if auth middleware returns.

Code versus spec​

  • GET /healthz and GET /readyz are registered by the router (internal/adapters/inbound/http/server.go) but absent from apis/openapi.yaml.
  • A key reused with a different request is 409 idempotency-key-reused (ADR 0010; it was 422 validation-failed before).