ingest
4 operations
POST /v1/ingest/{route}Receive a signed envelope from a device or gatewayPOST /v1/gateways/{id}/station-delegations/claimAn edge station claims an operator's sign-inPOST /v1/gateways/{id}/station-syncAn edge station asks the state of its sign-ins and its label dataPOST /v1/gateways/{id}/station-actionsAn edge station replays an operator's offline action
POST /v1/ingest/{route}
Receive a signed envelope from a device or gateway
Authentication: deviceMtls · ingestEnvelope
The path parameter route spans {tenant}/{site}/{device}/{kind}[/{eventType}] and includes slashes (the server pattern is /v1/ingest/{route*}). The body is a signed envelope (envelope version 1, spec agritrace.iot/1.0), which the server validates against its full schema, served at /developers/downloads/envelope-v1.schema.json (event types at /developers/downloads/event-types-v1.json, capabilities at /developers/downloads/capabilities-v1.json, device profiles below /developers/downloads/profiles/); that schema is not inlined here, so the request schema is open (additionalProperties: true). Over mTLS the certificate CN must match the device or its gateway. Statuses: 202 accepted or quarantined, 409 duplicate, 503 for a rejection that may resolve itself (unknown_device, unknown_key), other rejections 4xx. Every outcome that comes from the ingest service carries an IngestResult body; 400 and 413 can also come from the HTTP layer with an Error body. A pack event (#136: profile vn.agritrace.pack-station, one pack.carton reading per carton, the seal number in context.seal) is compared with the lot's packing records: the lot, its facility and the sending device's, the seal number (the lot's pack seal once it is packed), and every carton's fruits and net mass. Any difference is quarantined with the reason pack_mismatch: <differences> and a high pack_mismatch alert, and holds the lot until it is reviewed. A status envelope whose device id is a registered gateway's is that gateway's status heartbeat (#24, profile vn.agritrace.gateway): signed with one of the gateway's own keys, over mTLS from that gateway, with the readings of that profile only, else it is rejected (profile_mismatch, invalid_content, key_not_authorized). It is not stored as an envelope: the server keeps the gateway's newest heartbeat (GET /v1/gateways/{id}/heartbeat), and answers 202 accepted, or 409 duplicate for the heartbeat it keeps and, with the reason superseded, for an older one. Ordering: by seq, except for signed heartbeats, which also carry the gateway's own clock: a signed heartbeat with a lower seq but a later time than the kept one is kept (a gateway that was reset counts its seq from 0 again), and a signed heartbeat with a higher seq but an earlier time is answered superseded; an unsigned one is ordered by seq alone. A heartbeat dated more than the server's maximum future skew past its clock is rejected with 400 future_timestamp (a device envelope gets a 202 quarantine instead), so it never freezes the kept one. The other rejection reasons are those of a device envelope. #134: a message over its company's ingest quota (the company of the certificate's device or gateway, whatever the route names) answers 429 too_many_requests with Retry-After and an Error body before the body is read; the device sends it again later. A request without a client certificate (plain HTTP, or TLS without one), or with a certificate of no registered device or gateway (which the ingest then rejects), never takes a company's quota: it takes its client address's own bucket, of the default ingest quota, and answers the same 429 over it.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
routerequired | path | string |
|
Request body
Envelope (required)
Media type: application/json
Example request · application/json
{
"spec": "agritrace.iot/1.0",
"id": "3f2b8f0e-6a39-4f7e-9b1e-0d6c1c5e7a11",
"kind": "event",
"eventType": "inspect",
"device": {
"id": "knk-1",
"profile": "vn.agritrace.durian-knocker@1.0.0",
"gateway": "gw-01"
},
"time": "2026-09-30T08:00:00.000+07:00",
"seq": 0,
"context": {
"lot": "LOT-A",
"facility": "66-DL-SR-0001-CHN"
},
"readings": [
{
"capability": "produce.maturity_index",
"value": 82,
"unit": "%"
}
]
}Responses
| Status | Type | Description |
|---|---|---|
| 202 | IngestResultapplication/json | Stored. |
| 400 | IngestResult | Errorapplication/json | Rejected as malformed (malformed, unsupported_spec, bad_route, route_mismatch, bad_time; IngestResult), or a bad X-Request-Id (Error). |
| 401 | IngestResultapplication/json | Rejected: missing_signature or bad_signature. |
| 403 | IngestResultapplication/json | Rejected: key_not_authorized, peer_mismatch, tenant_mismatch, device_inactive or company_read_only (SELF-2-4, #193: the device's company is leaving CropPath or has left). |
| 405 | Errorapplication/json | The path exists but not for this method. |
| 409 | IngestResultapplication/json | Duplicate of a stored envelope (same id and content). Permanent for the sender; nothing was changed. |
| 413 | IngestResult | Errorapplication/json | Rejected as payload_too_large (IngestResult), or the request body is over 1 MiB (Error). |
| 422 | IngestResultapplication/json | Rejected: id_conflict (same id, different content). An alert is raised. |
| 500 | Errorapplication/json | Unexpected failure; the detail is only in the server log. |
| 503 | IngestResultapplication/json | Rejected with unknown_device or unknown_key: the registry may catch up, so the sender retries. |
Response headers
| Name | Status | Type | Description |
|---|---|---|---|
X-Request-Id | 202 | string | Request id: the caller's |
X-Request-Id | 400 | string | Request id: the caller's |
X-Request-Id | 401 | string | Request id: the caller's |
X-Request-Id | 403 | string | Request id: the caller's |
X-Request-Id | 405 | string | Request id: the caller's |
Allow | 405 | string | Comma-separated methods the path accepts. |
X-Request-Id | 409 | string | Request id: the caller's |
X-Request-Id | 413 | string | Request id: the caller's |
X-Request-Id | 422 | string | Request id: the caller's |
X-Request-Id | 500 | string | Request id: the caller's |
X-Request-Id | 503 | string | Request id: the caller's |
Retry-After | 503 | string | Seconds to wait before retrying. |
Example responses
Response 202 · application/json · accepted
{
"status": "accepted",
"id": "3f2b8f0e-6a39-4f7e-9b1e-0d6c1c5e7a11",
"reasons": []
}Response 202 · application/json · quarantined
{
"status": "quarantined",
"id": "3f2b8f0e-6a39-4f7e-9b1e-0d6c1c5e7a11",
"reasons": [
"volume_exceeds_cap"
]
}Response 400 · application/json · rejected
{
"status": "rejected",
"id": null,
"reasons": [
"malformed"
]
}Response 400 · application/json · bad_request_id
{
"error": "bad request id",
"code": "bad_request_id"
}Response 401 · application/json
{
"status": "rejected",
"id": "3f2b8f0e-6a39-4f7e-9b1e-0d6c1c5e7a11",
"reasons": [
"bad_signature"
]
}Response 403 · application/json
{
"status": "rejected",
"id": "3f2b8f0e-6a39-4f7e-9b1e-0d6c1c5e7a11",
"reasons": [
"tenant_mismatch"
]
}Response 405 · application/json
{
"error": "method not allowed",
"code": "method_not_allowed"
}Response 409 · application/json
{
"status": "duplicate",
"id": "3f2b8f0e-6a39-4f7e-9b1e-0d6c1c5e7a11",
"reasons": []
}Response 413 · application/json · rejected
{
"status": "rejected",
"id": null,
"reasons": [
"payload_too_large"
]
}Response 413 · application/json · body_too_large
{
"error": "body too large",
"code": "body_too_large"
}Response 422 · application/json
{
"status": "rejected",
"id": "3f2b8f0e-6a39-4f7e-9b1e-0d6c1c5e7a11",
"reasons": [
"id_conflict"
]
}Response 500 · application/json
{
"error": "internal error",
"code": "internal_error"
}Response 503 · application/json
{
"status": "rejected",
"id": "3f2b8f0e-6a39-4f7e-9b1e-0d6c1c5e7a11",
"reasons": [
"unknown_device"
]
}POST /v1/gateways/{id}/station-delegations/claim
An edge station claims an operator's sign-in
Authentication: deviceMtls · claimStationSignIn
#85 (owner decision 2026-10-17, option b): operators keep working at an edge station with the WAN down. The station claims the sign-in whose one-time code the operator typed on its screen (any case; spaces and hyphens ignored): once, while the code is valid, only at the gateway it was issued for, and only while the operator's account is active and the operator may still record fruit actions at the station's facility (else 403 operator_not_allowed; disabling the account or turning the membership off revokes the sign-in: 404). The answer is the sign-in (the operator's opaque id and display name, its end), the label data of the fruits of the open lots at the station's facility (newest first, at most 2000), which its printer queue prints from with the WAN down, the highest seq the cloud recorded from the station (last_seq, which its action counter moves above) and the cloud's time (the station counts the sign-in's end from it on its monotonic clock). One audit row (station.delegation.claim, actor the operator) in the company's activity log. The body is signed with one of the gateway's own active keys (ES256 over the canonical JSON of every member but sig, as an envelope). Over mTLS the client certificate must be the gateway's. No principal: the signature is the authentication. #326: with label_code=1 each label also has the fruit's lookup code (label_code, #288), the 15-character code the station's fruit label prints for a person whose QR code cannot be scanned; the scan page and GET /v1/public/resolve read it. Added after the partner SDK 0.2.0 (x-not-in-sdk): not part of the generated SDK clients.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | Gateway id (the edge station's). |
label_codeoptional | query | "0" | "1" | #326: |
Request body
StationClaimRequest (required)
Media type: application/json
Example request · application/json
{
"gateway": "gw-01",
"time": "2026-09-28T08:40:00+07:00",
"code": "K7MQ2XPA",
"sig": {
"alg": "ES256",
"kid": "gw-01",
"value": "q6bJ0tM1g2pUo7k9wqzQyLhB4mF3aVxN8cR5sTdE1uYiHjKlZ0oP9nW2eQ3rT4yU6iO7pA8sD9fG0hJ1kL2zXc"
}
}Responses
| Status | Type | Description |
|---|---|---|
| 200 | StationClaimapplication/json | Claimed. |
| 400 | Errorapplication/json | A malformed request, or |
| 403 | Errorapplication/json | Refused: the signature is not from an active key of this gateway, a bad signature, an inactive gateway, a client certificate of another identity, a request more than 300 s off the server's time, or a company that is leaving CropPath. Or the operator may no longer record fruit actions at the station's facility ( |
| 404 | Errorapplication/json | No such gateway, or no sign-in with this code waiting at this station (unknown, used, expired or revoked). |
| 405 | Errorapplication/json | The path exists but not for this method. |
| 413 | Errorapplication/json | The request body is over 1 MiB. |
| 500 | Errorapplication/json | Unexpected failure; the detail is only in the server log. |
Response headers
| Name | Status | Type | Description |
|---|---|---|---|
X-Request-Id | 200 | string | Request id: the caller's |
X-Request-Id | 400 | string | Request id: the caller's |
X-Request-Id | 403 | string | Request id: the caller's |
X-Request-Id | 404 | string | Request id: the caller's |
X-Request-Id | 405 | string | Request id: the caller's |
Allow | 405 | string | Comma-separated methods the path accepts. |
X-Request-Id | 413 | string | Request id: the caller's |
X-Request-Id | 500 | string | Request id: the caller's |
Example responses
Response 200 · application/json
{
"delegation": {
"id": "3f9c2b1e8a7d4c6b9e0f1a2b3c4d5e6f",
"operator": "user-7",
"name": "Lan",
"issued_at": 1790560000,
"claimed_at": 1790560100,
"expires_at": 1790588800
},
"labels": [
{
"code": "Q-014-0129",
"lot": "LO-260928-014",
"n": 129,
"round": 0,
"status": "recorded",
"qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7"
}
],
"last_seq": 41,
"time": 1790560100
}Response 400 · application/json · malformed
{
"error": "malformed: the request's fields",
"code": "malformed"
}Response 400 · application/json · code
{
"error": "bad code: the sign-in code shown in the console",
"code": "bad_code"
}Response 400 · application/json · bad_label_code
{
"error": "bad label_code",
"code": "bad_label_code"
}Response 403 · application/json · key
{
"error": "key not authorized: not an active key of this gateway",
"code": "key_not_authorized"
}Response 403 · application/json · signature
{
"error": "bad signature",
"code": "bad_signature"
}Response 403 · application/json · stale
{
"error": "stale request: the station's time is more than 300 s off",
"code": "stale_request"
}Response 403 · application/json · operator
{
"error": "operator not allowed: the operator may no longer act for the company",
"code": "operator_not_allowed"
}Response 404 · application/json
{
"error": "unknown code: no sign-in with this code is waiting at this station",
"code": "unknown_code"
}Response 405 · application/json
{
"error": "method not allowed",
"code": "method_not_allowed"
}Response 413 · application/json
{
"error": "body too large",
"code": "body_too_large"
}Response 500 · application/json
{
"error": "internal error",
"code": "internal_error"
}POST /v1/gateways/{id}/station-sync
An edge station asks the state of its sign-ins and its label data
Authentication: deviceMtls · syncStation
#85 (owner decision 2026-10-17, option b): operators keep working at an edge station with the WAN down. Once it reaches the cloud, the station asks the state of the sign-ins it holds (active, revoked, expired, or unknown for one that is not this station's or never claimed; revoked too for one whose operator's account is disabled or who may no longer record fruit actions at the station's facility) and refreshes its label data and last_seq; it ends the local session of a sign-in that is no longer active. A read: no audit row. The body is signed with one of the gateway's own active keys (ES256 over the canonical JSON of every member but sig, as an envelope). Over mTLS the client certificate must be the gateway's. No principal: the signature is the authentication. #326: with label_code=1 each label also has the fruit's lookup code (label_code, #288), the 15-character code the station's fruit label prints for a person whose QR code cannot be scanned; the scan page and GET /v1/public/resolve read it. Added after the partner SDK 0.2.0 (x-not-in-sdk): not part of the generated SDK clients.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | Gateway id (the edge station's). |
label_codeoptional | query | "0" | "1" | #326: |
Request body
StationSyncRequest (required)
Media type: application/json
Example request · application/json
{
"gateway": "gw-01",
"time": "2026-09-28T10:00:00+07:00",
"delegations": [
"3f9c2b1e8a7d4c6b9e0f1a2b3c4d5e6f"
],
"sig": {
"alg": "ES256",
"kid": "gw-01",
"value": "q6bJ0tM1g2pUo7k9wqzQyLhB4mF3aVxN8cR5sTdE1uYiHjKlZ0oP9nW2eQ3rT4yU6iO7pA8sD9fG0hJ1kL2zXc"
}
}Responses
| Status | Type | Description |
|---|---|---|
| 200 | StationSyncapplication/json | The states and the labels. |
| 400 | Errorapplication/json | A malformed request, or |
| 403 | Errorapplication/json | Refused: the signature is not from an active key of this gateway, a bad signature, an inactive gateway, a client certificate of another identity, a request more than 300 s off the server's time, or a company that is leaving CropPath. |
| 404 | Errorapplication/json | No such gateway. |
| 405 | Errorapplication/json | The path exists but not for this method. |
| 413 | Errorapplication/json | The request body is over 1 MiB. |
| 500 | Errorapplication/json | Unexpected failure; the detail is only in the server log. |
Response headers
| Name | Status | Type | Description |
|---|---|---|---|
X-Request-Id | 200 | string | Request id: the caller's |
X-Request-Id | 400 | string | Request id: the caller's |
X-Request-Id | 403 | string | Request id: the caller's |
X-Request-Id | 404 | string | Request id: the caller's |
X-Request-Id | 405 | string | Request id: the caller's |
Allow | 405 | string | Comma-separated methods the path accepts. |
X-Request-Id | 413 | string | Request id: the caller's |
X-Request-Id | 500 | string | Request id: the caller's |
Example responses
Response 200 · application/json
{
"delegations": {
"3f9c2b1e8a7d4c6b9e0f1a2b3c4d5e6f": "active"
},
"labels": [
{
"code": "Q-014-0129",
"lot": "LO-260928-014",
"n": 129,
"round": 0,
"status": "recorded",
"qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7"
}
],
"last_seq": 41,
"time": 1790564400
}Response 400 · application/json · malformed
{
"error": "malformed: the request's fields",
"code": "malformed"
}Response 400 · application/json · ids
{
"error": "bad delegations: at most 64 delegation ids",
"code": "bad_delegations"
}Response 400 · application/json · bad_label_code
{
"error": "bad label_code",
"code": "bad_label_code"
}Response 403 · application/json · key
{
"error": "key not authorized: not an active key of this gateway",
"code": "key_not_authorized"
}Response 403 · application/json · signature
{
"error": "bad signature",
"code": "bad_signature"
}Response 403 · application/json · stale
{
"error": "stale request: the station's time is more than 300 s off",
"code": "stale_request"
}Response 404 · application/json
{
"error": "not found: gw-01",
"code": "not_found"
}Response 405 · application/json
{
"error": "method not allowed",
"code": "method_not_allowed"
}Response 413 · application/json
{
"error": "body too large",
"code": "body_too_large"
}Response 500 · application/json
{
"error": "internal error",
"code": "internal_error"
}POST /v1/gateways/{id}/station-actions
An edge station replays an operator's offline action
Authentication: deviceMtls · replayStationAction
#85 (owner decision 2026-10-17, option b): operators keep working at an edge station with the WAN down. One action an operator recorded at the station with the WAN down, signed by the station as recorded offline at station X for operator Y, replayed in the station's order once it is back: accept and remeasure are applied as that operator's fruit actions with every existing check (lot closed or sampled, transition, measurement in review), the record id as idempotency key and no set_session push; print records that the station printed the fruit's label from its local queue. The cloud checks that the sign-in is this station's and of this company (else 404 like a missing one), claimed, not revoked, the record's time within it (300 s of slack; for a record stamped time_source unsynced, its since_claim_s alone, required: else 403 unsynced_clock), since_claim_s within the sign-in's length (300 s of slack) and the replay within 72 hours of its end (else 403), that the operator may still act on the fruit's facility, which must be the station's (403, 404), that seq is above every action the cloud recorded from the station (409 out_of_order), and that every envelope named in after is stored or was rejected (else 503 not_stored_yet, Retry-After: the station tries again, so an acceptance never overtakes the knock it accepts). A re-measure's offline round must be the fruit's next round: otherwise 409 round_conflict, nothing changes on the fruit, the conflict is recorded, and the knocks the station's devices stamped with that round do not bind (superseded_round). The same record again answers what it answered the first time (200 for an applied one) and writes nothing; other content under a stored id is 409 id_conflict. Each recorded action writes exactly one audit row (station.action, actor the operator, after.station the gateway). A fruit with an accept or re-measure from a station is at most Device-recorded (ADR 0001). The body is signed with one of the gateway's own active keys (ES256 over the canonical JSON of every member but sig, as an envelope). Over mTLS the client certificate must be the gateway's. No principal: the signature is the authentication. Added after the partner SDK 0.2.0 (x-not-in-sdk): not part of the generated SDK clients.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | Gateway id (the edge station's). |
Request body
StationActionRecord (required)
Media type: application/json
Example request · application/json
{
"v": 1,
"id": "9b2e4c1a-7f3d-4e8b-a6c5-0d1e2f3a4b5c",
"type": "remeasure",
"gateway": "gw-01",
"seq": 12,
"delegation": "3f9c2b1e8a7d4c6b9e0f1a2b3c4d5e6f",
"operator": "user-7",
"fruit": "Q-014-0129",
"round": 1,
"recorded_at": "2026-09-28T09:12:03.120+07:00",
"time_source": "ntp",
"after": [
"0b9c2f4e-7d1a-4c3e-9f8b-2a6d5e1c7b30"
],
"sig": {
"alg": "ES256",
"kid": "gw-01",
"value": "q6bJ0tM1g2pUo7k9wqzQyLhB4mF3aVxN8cR5sTdE1uYiHjKlZ0oP9nW2eQ3rT4yU6iO7pA8sD9fG0hJ1kL2zXc"
}
}Responses
| Status | Type | Description |
|---|---|---|
| 200 | StationActionResultapplication/json | Applied before (a lost acknowledgement): the stored answer. |
| 201 | StationActionResultapplication/json | Applied. |
| 400 | Errorapplication/json | A malformed record. |
| 403 | Errorapplication/json | Refused: the station's key or the sign-in (expired, by |
| 404 | Errorapplication/json | No such gateway, no such sign-in at this station (another station's or another company's), or no such fruit at this station. |
| 405 | Errorapplication/json | The path exists but not for this method. |
| 409 | Errorapplication/json | Not applied: a round conflict (recorded; the same record again answers it again), an action replayed out of the station's order, another record under the id, or a check of the fruit action (lot closed, transition, review). |
| 413 | Errorapplication/json | Over 8192 bytes. |
| 500 | Errorapplication/json | Unexpected failure; the detail is only in the server log. |
| 503 | Errorapplication/json | An envelope the action follows is not stored yet; try again later. |
Response headers
| Name | Status | Type | Description |
|---|---|---|---|
X-Request-Id | 200 | string | Request id: the caller's |
X-Request-Id | 201 | string | Request id: the caller's |
X-Request-Id | 400 | string | Request id: the caller's |
X-Request-Id | 403 | string | Request id: the caller's |
X-Request-Id | 404 | string | Request id: the caller's |
X-Request-Id | 405 | string | Request id: the caller's |
Allow | 405 | string | Comma-separated methods the path accepts. |
X-Request-Id | 409 | string | Request id: the caller's |
X-Request-Id | 413 | string | Request id: the caller's |
X-Request-Id | 500 | string | Request id: the caller's |
X-Request-Id | 503 | string | Request id: the caller's |
Retry-After | 503 | string | Seconds to wait before retrying. |
Example responses
Response 200 · application/json
{
"id": "9b2e4c1a-7f3d-4e8b-a6c5-0d1e2f3a4b5c",
"type": "accept",
"outcome": "applied",
"seq": 11,
"fruit": {
"code": "Q-014-0129",
"status": "recorded",
"accepted_at": 1790561523,
"round": 0
}
}Response 201 · application/json
{
"id": "9b2e4c1a-7f3d-4e8b-a6c5-0d1e2f3a4b5c",
"type": "remeasure",
"outcome": "applied",
"seq": 12,
"fruit": {
"code": "Q-014-0129",
"status": "awaiting_device",
"accepted_at": null,
"round": 1
}
}Response 400 · application/json · malformed
{
"error": "malformed: round",
"code": "malformed"
}Response 400 · application/json · gateway
{
"error": "gateway mismatch: the request names another gateway",
"code": "gateway_mismatch"
}Response 400 · application/json · future
{
"error": "future timestamp: recorded after the server's time",
"code": "future_timestamp"
}Response 403 · application/json · key
{
"error": "key not authorized: not an active key of this gateway",
"code": "key_not_authorized"
}Response 403 · application/json · expired
{
"error": "delegation expired",
"code": "delegation_expired"
}Response 403 · application/json · revoked
{
"error": "delegation revoked",
"code": "delegation_revoked"
}Response 403 · application/json · unsynced
{
"error": "unsynced clock: the station's clock was off and the action carries no since_claim_s",
"code": "unsynced_clock"
}Response 403 · application/json · operator
{
"error": "operator not allowed: the operator may no longer act for the company",
"code": "operator_not_allowed"
}Response 404 · application/json · delegation
{
"error": "not found: no such delegation at this station",
"code": "not_found"
}Response 404 · application/json · fruit
{
"error": "not found: no such fruit at this station",
"code": "not_found"
}Response 405 · application/json
{
"error": "method not allowed",
"code": "method_not_allowed"
}Response 409 · application/json · round
{
"error": "round conflict: the station numbered round 1, the fruit's next round is 2",
"code": "round_conflict"
}Response 409 · application/json · order
{
"error": "out of order: the station already replayed action 12",
"code": "out_of_order"
}Response 409 · application/json · id
{
"error": "id conflict: another record is stored under this id",
"code": "id_conflict"
}Response 409 · application/json · transition
{
"error": "invalid transition: awaiting_device to accept",
"code": "invalid_transition"
}Response 413 · application/json
{
"error": "too large: at most 8192 bytes",
"code": "too_large"
}Response 500 · application/json
{
"error": "internal error",
"code": "internal_error"
}Response 503 · application/json
{
"error": "not stored yet: an envelope the action follows has not reached the cloud",
"code": "not_stored_yet"
}