CropPath 开发者

API 参考

envelopes

3 个操作

GET /v1/envelopes

Device message log: stored envelopes, newest first

身份验证:cookie, bearer, oauth2 · OAuth2 作用域: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.

参数

名称位置类型说明
cursor
可选
querystring

next_cursor of the previous page.

limit
可选
queryinteger

Page size, 1 to 200.

device
可选
querystring

Only this device's envelopes (exact device id).

site
可选
querystring

Only envelopes routed from this site (exact).

facility
可选
querystring

Only envelopes recorded at this facility (exact code; the envelope context's facility).

kind
可选
query"telemetry" | "event" | "status"

Only envelopes of this kind.

event_type
可选
querystring

Only events of this type (exact).

status
可选
query"accepted" | "quarantined" | "rejected_after_review"

Only envelopes in this state.

lot
可选
querystring

Only envelopes whose context names this lot (exact).

from
可选
querystring

Only envelopes received at or after this time (epoch seconds, at most 6 decimals).

to
可选
querystring

Only envelopes received before this time (epoch seconds, at most 6 decimals).

响应

状态码类型说明
200EnvelopePage
application/json

One page of envelopes.

400Error
application/json

A cursor this API did not issue, a limit out of range, a bad filter value or a bad X-Request-Id.

401Error
application/json

No valid session, API token or legacy token.

403Error
application/json

The caller is known but refused: role not permitted or tenant not allowed (X-Tenant).

405Error
application/json

The path exists but not for this method. Allow lists the methods it accepts.

500Error
application/json

Unexpected failure; the detail is only in the server log.

响应头

名称状态码类型说明
X-Request-Id200string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id400string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id401string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id403string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id405string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

Allow405string

Comma-separated methods the path accepts.

X-Request-Id500string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

响应示例

响应 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
}
响应 400 · application/json · bad_cursor
{
  "error": "bad cursor",
  "code": "bad_cursor"
}
响应 400 · application/json · bad_limit
{
  "error": "bad limit",
  "code": "bad_limit"
}
响应 400 · application/json · bad_filter
{
  "error": "bad filter: status",
  "code": "bad_filter"
}
响应 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
响应 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
响应 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/envelopes/stream

Live tail of the device message log (server-sent events)

身份验证:cookie, bearer, oauth2 · OAuth2 作用域: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.

参数

名称位置类型说明
Last-Event-ID
可选
headerstring

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

after
可选
queryinteger

Send the envelopes stored or reviewed after this rx_seq; a decimal integer from 0 to 2^63-1. Without it (and without Last-Event-ID) the stream starts at the tenant's newest rx_seq: only what arrives from now on.

device
可选
querystring

Only this device's envelopes (exact device id).

site
可选
querystring

Only envelopes routed from this site (exact).

facility
可选
querystring

Only envelopes recorded at this facility (exact code; the envelope context's facility).

kind
可选
query"telemetry" | "event" | "status"

Only envelopes of this kind.

event_type
可选
querystring

Only events of this type (exact).

status
可选
query"accepted" | "quarantined" | "rejected_after_review"

Only envelopes in this state.

lot
可选
querystring

Only envelopes whose context names this lot (exact).

from
可选
querystring

Only envelopes received at or after this time (epoch seconds, at most 6 decimals).

to
可选
querystring

Only envelopes received before this time (epoch seconds, at most 6 decimals).

响应

状态码类型说明
200string
text/event-stream

The event stream.

400Error
application/json

A malformed Last-Event-ID or after, a bad filter value or a bad X-Request-Id.

401Error
application/json

No valid session, API token or legacy token.

403Error
application/json

The caller is known but refused: role not permitted or tenant not allowed (X-Tenant).

405Error
application/json

The path exists but not for this method. Allow lists the methods it accepts.

500Error
application/json

Unexpected failure; the detail is only in the server log.

503Error
application/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 Retry-After seconds.

响应头

名称状态码类型说明
X-Request-Id200string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

Cache-Control200string

no-cache.

X-Accel-Buffering200string

no: proxies must not buffer the stream.

X-Request-Id400string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id401string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id403string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id405string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

Allow405string

Comma-separated methods the path accepts.

X-Request-Id500string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id503string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

Retry-After503string

Seconds to wait before retrying.

响应示例

响应 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

响应 400 · application/json · bad_last_event_id
{
  "error": "bad last event id",
  "code": "bad_last_event_id"
}
响应 400 · application/json · bad_cursor
{
  "error": "bad cursor",
  "code": "bad_cursor"
}
响应 400 · application/json · bad_filter
{
  "error": "bad filter: status",
  "code": "bad_filter"
}
响应 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
响应 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
响应 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}
响应 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

身份验证:cookie, bearer, oauth2 · OAuth2 作用域: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.

参数

名称位置类型说明
id
必填
pathstring

Envelope id.

响应

状态码类型说明
200EnvelopeDetail
application/json

The envelope.

400Error
application/json

The X-Request-Id header is present and malformed.

401Error
application/json

No valid session, API token or legacy token.

403Error
application/json

The caller is known but refused: role not permitted or tenant not allowed (X-Tenant).

404Error
application/json

No such envelope for this tenant (or outside the operator's facilities).

405Error
application/json

The path exists but not for this method. Allow lists the methods it accepts.

500Error
application/json

Unexpected failure; the detail is only in the server log.

响应头

名称状态码类型说明
X-Request-Id200string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id400string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id401string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id403string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id404string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

X-Request-Id405string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

Allow405string

Comma-separated methods the path accepts.

X-Request-Id500string

Request id: the caller's X-Request-Id when it is 1 to 64 of A-Z a-z 0-9 . _ -, otherwise a generated one.

响应示例

响应 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"
  }
}
响应 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
响应 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
响应 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
响应 404 · application/json
{
  "error": "not found: 0c6f3a0e-5b8e-4a59-9e57-3d7c0f7d1a11",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}