envelopes
3 operations
GET /v1/envelopesDevice message log: stored envelopes, newest firstGET /v1/envelopes/streamLive tail of the device message log (server-sent events)GET /v1/envelopes/{id}One stored envelope with its signed payload and signature status
GET /v1/envelopes
Device message log: stored envelopes, newest first
Authentication: cookie, bearer, oauth2 · OAuth2 scopes: envelope_read · listEnvelopes
Every envelope ingest stored for the tenant (accepted, quarantined or rejected after review; never the messages refused before storage), newest first by received_at then id, with keyset pagination (default 50, at most 200 per page) and exact-match filters. A page that no index serves (a site, kind, event_type or lot filter, two of device, status and facility, or an operator scope of several facilities) reads at most 1000 envelopes of the tenant, so it may hold fewer items than the limit, even none, while next_cursor is set: follow next_cursor until it is null. Every filter value is checked before any query (400 bad filter: <name>). Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the envelopes recorded at its facilities); a lab is refused. Not audited.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
cursoroptional | query | string |
|
limitoptional | query | integer | Page size, 1 to 200. |
deviceoptional | query | string | Only this device's envelopes (exact device id). |
siteoptional | query | string | Only envelopes routed from this site (exact). |
facilityoptional | query | string | Only envelopes recorded at this facility (exact code; the envelope context's |
kindoptional | query | "telemetry" | "event" | "status" | Only envelopes of this kind. |
event_typeoptional | query | string | Only events of this type (exact). |
statusoptional | query | "accepted" | "quarantined" | "rejected_after_review" | Only envelopes in this state. |
lotoptional | query | string | Only envelopes whose context names this lot (exact). |
fromoptional | query | string | Only envelopes received at or after this time (epoch seconds, at most 6 decimals). |
tooptional | query | string | Only envelopes received before this time (epoch seconds, at most 6 decimals). |
Responses
| Status | Type | Description |
|---|---|---|
| 200 | EnvelopePageapplication/json | One page of envelopes. |
| 400 | Errorapplication/json | A cursor this API did not issue, a limit out of range, a bad filter value or a bad X-Request-Id. |
| 401 | Errorapplication/json | No valid session, API token or legacy token. |
| 403 | Errorapplication/json | The caller is known but refused: role not permitted or tenant not allowed (X-Tenant). |
| 405 | Errorapplication/json | The path exists but not for this method. |
| 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 | 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 | 500 | string | Request id: the caller's |
Example responses
Response 200 · application/json
{
"items": [
{
"id": "0c6f3a0e-5b8e-4a59-9e57-3d7c0f7d1a11",
"device_id": "scl-st",
"site": "ph1",
"facility": "VN-TGPH-021",
"seq": 41,
"kind": "event",
"event_type": "receive",
"event_time": "2026-09-28T08:56:02.120+07:00",
"received_at": 1790000000.5,
"status": "accepted",
"reasons": [],
"lot": "LO-260928-014"
}
],
"next_cursor": null
}Response 400 · application/json · bad_cursor
{
"error": "bad cursor",
"code": "bad_cursor"
}Response 400 · application/json · bad_limit
{
"error": "bad limit",
"code": "bad_limit"
}Response 400 · application/json · bad_filter
{
"error": "bad filter: status",
"code": "bad_filter"
}Response 400 · application/json · bad_request_id
{
"error": "bad request id",
"code": "bad_request_id"
}Response 401 · application/json
{
"error": "missing or invalid token",
"code": "missing_or_invalid_token"
}Response 403 · application/json · role
{
"error": "role not permitted",
"code": "role_not_permitted"
}Response 403 · application/json · tenant
{
"error": "tenant not allowed",
"code": "tenant_not_allowed"
}Response 405 · application/json
{
"error": "method not allowed",
"code": "method_not_allowed"
}Response 500 · application/json
{
"error": "internal error",
"code": "internal_error"
}GET /v1/envelopes/stream
Live tail of the device message log (server-sent events)
Authentication: cookie, bearer, oauth2 · OAuth2 scopes: envelope_read · streamEnvelopes
A text/event-stream on the session stream's machinery (no Content-Length; Cache-Control: no-cache, X-Accel-Buffering: no; the connection closes when the stream ends). It starts with retry: 2000, then sends every envelope stored or reviewed after the resume point that passes the filters (the same as GET /v1/envelopes) as id: <rx_seq> / event: envelope / data: {rx_seq, envelope} (an EnvelopeSummary) in rx_seq order; a reviewed envelope is sent again with its new status. A : hb comment follows 15 s without output; there is no status or end event. The server polls once a second (at once while a backlog remains; one poll reads at most 1000 envelopes after the cursor, matching or not, and moves the cursor past them) and ends a stream after its lifetime (30 minutes by default; the client reconnects with Last-Event-ID). The resume point is the Last-Event-ID header when sent, else after, else the tenant's newest rx_seq. Envelopes stored before migration 15 have no rx_seq and are never streamed. The caps are shared with every other stream: at most 64 per backend process, half of them (32) for one tenant and 4 for one principal; above any of these the answer is 503 with Retry-After: 2. Authentication, the role check and the parameters are answered as JSON before any stream byte; the credential and the grant are checked again on every poll, so a logout, a revoked or expired session or API token, a disabled user, a password change or a lost grant ends the stream at once, and a grant moved to other facilities streams only those from the next poll. EventSource cannot send X-Tenant: a session principal streams its default tenant. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the envelopes recorded at its facilities); a lab is refused. Not audited.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
Last-Event-IDoptional | header | string | The id of the last event received (sent by EventSource on reconnect): resume after this rx_seq; a decimal integer from 0 to 2^63-1. Takes precedence over |
afteroptional | query | integer | Send the envelopes stored or reviewed after this rx_seq; a decimal integer from 0 to 2^63-1. Without it (and without |
deviceoptional | query | string | Only this device's envelopes (exact device id). |
siteoptional | query | string | Only envelopes routed from this site (exact). |
facilityoptional | query | string | Only envelopes recorded at this facility (exact code; the envelope context's |
kindoptional | query | "telemetry" | "event" | "status" | Only envelopes of this kind. |
event_typeoptional | query | string | Only events of this type (exact). |
statusoptional | query | "accepted" | "quarantined" | "rejected_after_review" | Only envelopes in this state. |
lotoptional | query | string | Only envelopes whose context names this lot (exact). |
fromoptional | query | string | Only envelopes received at or after this time (epoch seconds, at most 6 decimals). |
tooptional | query | string | Only envelopes received before this time (epoch seconds, at most 6 decimals). |
Responses
| Status | Type | Description |
|---|---|---|
| 200 | stringtext/event-stream | The event stream. |
| 400 | Errorapplication/json | A malformed |
| 401 | Errorapplication/json | No valid session, API token or legacy token. |
| 403 | Errorapplication/json | The caller is known but refused: role not permitted or tenant not allowed (X-Tenant). |
| 405 | Errorapplication/json | The path exists but not for this method. |
| 500 | Errorapplication/json | Unexpected failure; the detail is only in the server log. |
| 503 | Errorapplication/json | Too many concurrent streams on this backend process, for the caller's tenant or for the caller (the caps every stream shares); poll GET /v1/envelopes instead and retry after |
Response headers
| Name | Status | Type | Description |
|---|---|---|---|
X-Request-Id | 200 | string | Request id: the caller's |
Cache-Control | 200 | string |
|
X-Accel-Buffering | 200 | string |
|
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 | 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 · text/event-stream
retry: 2000
id: 8812
event: envelope
data: {"rx_seq":8812,"envelope":{"id":"0c6f3a0e-5b8e-4a59-9e57-3d7c0f7d1a11","device_id":"scl-st","site":"ph1","facility":"VN-TGPH-021","seq":41,"kind":"event","event_type":"receive","event_time":"2026-09-28T08:56:02.120+07:00","received_at":1790000000.5,"status":"accepted","reasons":[],"lot":"LO-260928-014"}}
: hb
Response 400 · application/json · bad_last_event_id
{
"error": "bad last event id",
"code": "bad_last_event_id"
}Response 400 · application/json · bad_cursor
{
"error": "bad cursor",
"code": "bad_cursor"
}Response 400 · application/json · bad_filter
{
"error": "bad filter: status",
"code": "bad_filter"
}Response 400 · application/json · bad_request_id
{
"error": "bad request id",
"code": "bad_request_id"
}Response 401 · application/json
{
"error": "missing or invalid token",
"code": "missing_or_invalid_token"
}Response 403 · application/json · role
{
"error": "role not permitted",
"code": "role_not_permitted"
}Response 403 · application/json · tenant
{
"error": "tenant not allowed",
"code": "tenant_not_allowed"
}Response 405 · application/json
{
"error": "method not allowed",
"code": "method_not_allowed"
}Response 500 · application/json
{
"error": "internal error",
"code": "internal_error"
}Response 503 · application/json
{
"error": "too many streams",
"code": "too_many_streams"
}GET /v1/envelopes/{id}
One stored envelope with its signed payload and signature status
Authentication: cookie, bearer, oauth2 · OAuth2 scopes: envelope_read · getEnvelope
The envelope's summary columns, its growing area, the signed payload exactly as stored and the signature checked again with the stored key it names (see EnvelopeDetail). Another tenant's envelope, or one outside an operator's facilities, answers 404 like a missing one. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the envelopes recorded at its facilities); a lab is refused. Not audited.
Parameters
| Name | In | Type | Description |
|---|---|---|---|
idrequired | path | string | Envelope id. |
Responses
| Status | Type | Description |
|---|---|---|
| 200 | EnvelopeDetailapplication/json | The envelope. |
| 400 | Errorapplication/json | The X-Request-Id header is present and malformed. |
| 401 | Errorapplication/json | No valid session, API token or legacy token. |
| 403 | Errorapplication/json | The caller is known but refused: role not permitted or tenant not allowed (X-Tenant). |
| 404 | Errorapplication/json | No such envelope for this tenant (or outside the operator's facilities). |
| 405 | Errorapplication/json | The path exists but not for this method. |
| 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 | 401 | 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 | 500 | string | Request id: the caller's |
Example responses
Response 200 · application/json
{
"id": "0c6f3a0e-5b8e-4a59-9e57-3d7c0f7d1a11",
"device_id": "scl-st",
"site": "ph1",
"facility": "VN-TGPH-021",
"seq": 41,
"kind": "event",
"event_type": "receive",
"event_time": "2026-09-28T08:56:02.120+07:00",
"received_at": 1790000000.5,
"status": "accepted",
"reasons": [],
"lot": "LO-260928-014",
"growing_area": null,
"payload": {
"spec": "agritrace.iot/1.0",
"id": "0c6f3a0e-5b8e-4a59-9e57-3d7c0f7d1a11",
"kind": "event",
"eventType": "receive",
"device": {
"id": "scl-st",
"profile": "vn.agritrace.scale-serial@1.0.0",
"gateway": "gw-01"
},
"seq": 41,
"time": "2026-09-28T08:56:02.120+07:00",
"readings": [
{
"capability": "mass.net",
"value": 3.42,
"unit": "kg"
}
],
"context": {
"lot": "LO-260928-014",
"facility": "VN-TGPH-021"
},
"sig": {
"alg": "ES256",
"kid": "gw-01",
"value": "MEUCIQ"
}
},
"signature": {
"status": "valid",
"kid": "gw-01",
"key_status": "active"
}
}Response 400 · application/json
{
"error": "bad request id",
"code": "bad_request_id"
}Response 401 · application/json
{
"error": "missing or invalid token",
"code": "missing_or_invalid_token"
}Response 403 · application/json · role
{
"error": "role not permitted",
"code": "role_not_permitted"
}Response 403 · application/json · tenant
{
"error": "tenant not allowed",
"code": "tenant_not_allowed"
}Response 404 · application/json
{
"error": "not found: 0c6f3a0e-5b8e-4a59-9e57-3d7c0f7d1a11",
"code": "not_found"
}Response 405 · application/json
{
"error": "method not allowed",
"code": "method_not_allowed"
}Response 500 · application/json
{
"error": "internal error",
"code": "internal_error"
}