CropPath 开发者

API 参考

labs

14 个操作

GET /v1/labs

Lab partners

身份验证:cookie, bearer · listLabs

Labs ordered by code, with keyset pagination (at most 100 per page). Allowed for platform_admin (every lab) and for a lab user signed in with a session (its own lab only; another lab answers 404 like a missing one). A lab principal without a lab (an API token) is refused 403. Not audited (a read).

参数

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

next_cursor of the previous page.

limit
可选
queryinteger

Page size, 1 to 100.

响应

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

One page of labs.

400Error
application/json

A cursor that is not one this API issued, a limit out of range, 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": [
    {
      "code": "LAB-VN-118",
      "name": "Phòng thử nghiệm mẫu",
      "accreditation": "VILAS 118 (ISO/IEC 17025)",
      "valid_to": "2027-12-31",
      "status": "active",
      "created_at": 1790000000.5,
      "updated_at": 1790000000.5,
      "in_force": true,
      "accreditation_body": "BoA (VILAS)",
      "accreditation_number": "VILAS 118",
      "accreditation_scope": "Cadmium (ICP-MS) and auramine O (LC-MS/MS) in fresh fruit"
    }
  ],
  "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_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/labs/{code}

A lab partner

身份验证:cookie, bearer · getLab

One lab. Allowed for platform_admin (every lab) and for a lab user signed in with a session (its own lab only; another lab answers 404 like a missing one). A lab principal without a lab (an API token) is refused 403. Not audited (a read).

参数

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

Lab code, e.g. LAB-VN-118.

响应

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

The lab.

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 lab, or a lab outside the caller's scope (a lab user's other labs).

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
{
  "code": "LAB-VN-118",
  "name": "Phòng thử nghiệm mẫu",
  "accreditation": "VILAS 118 (ISO/IEC 17025)",
  "valid_to": "2027-12-31",
  "status": "active",
  "created_at": 1790000000.5,
  "updated_at": 1790000000.5,
  "in_force": true,
  "accreditation_body": "BoA (VILAS)",
  "accreditation_number": "VILAS 118",
  "accreditation_scope": "Cadmium (ICP-MS) and auramine O (LC-MS/MS) in fresh fruit"
}
响应 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: LAB-VN-118",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/labs/{code}/keys

A lab's signing keys

身份验证:cookie, bearer · listLabKeys

Keys ordered by kid, with keyset pagination (at most 100 per page). Never returns key material, only fingerprints. Allowed for platform_admin (every lab) and for a lab user signed in with a session (its own lab only; another lab answers 404 like a missing one). A lab principal without a lab (an API token) is refused 403. Not audited (a read).

参数

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

Lab code, e.g. LAB-VN-118.

cursor
可选
querystring

next_cursor of the previous page.

limit
可选
queryinteger

Page size, 1 to 100.

响应

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

One page of keys.

400Error
application/json

A cursor that is not one this API issued, a limit out of range, 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).

404Error
application/json

No such lab, or a lab outside the caller's scope (a lab user's other labs).

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
{
  "items": [
    {
      "kid": "LAB-VN-118.2026",
      "lab": "LAB-VN-118",
      "status": "active",
      "created_at": 1790000000.5,
      "revoked_at": null,
      "revoke_reason": null,
      "revoked_by": null,
      "fingerprint_sha256": "19fcfa6012e7f761a1f1e408e6bc08ce10ce6a4347be82fd3c9ddf6a9fcfe0d9",
      "fingerprint": "19fc…e0d9",
      "custody": "lab"
    }
  ],
  "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_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"
}
响应 404 · application/json
{
  "error": "not found: LAB-VN-118",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/labs/{code}/keys

Register a lab signing key

身份验证:cookie, bearer · createLabKey

Registers an active EC P-256 public key of the lab. Key ids share one namespace with device and gateway keys: a taken or reserved kid is 409. Audited (lab_key.create; the PEM is never copied into the audit row). Allowed for platform_admin (every lab) and for a lab user signed in with a session (its own lab only; another lab answers 404 like a missing one). A lab principal without a lab (an API token) is refused 403.

参数

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

Lab code, e.g. LAB-VN-118.

Idempotency-Key
可选
headerstring

Makes a retry of this request safe (#169). A client-chosen key, 1 to 255 visible ASCII characters (a UUID is a good choice), scoped to the caller's tenant and principal (session user, API token or legacy token). The first request with a key runs; when it answers 2xx, that response (status, body and headers) is stored and replayed for 24 hours to every request with the same key and the same method, path, query and body bytes, marked Idempotent-Replayed: true, without running the operation again or writing another audit row. The same key with another request is 422 idempotency_key_mismatch; while the first request still runs it is 409 idempotency_key_in_use with Retry-After. A request that fails before its operation commits releases the key, so it may be sent again (corrected) with the same key. An operation that committed is never run again under its key, even when its response could not be recorded (a 500 after the commit; a server stop or a database error between the commit and the record): the retry is 409 idempotency_key_in_use for up to 5 minutes, then 409 idempotency_key_used until the key expires. A malformed or repeated header is 400 invalid_idempotency_key.

请求体

LabKeyCreate (必填)

媒体类型: application/json

请求示例 · application/json
{
  "kid": "LAB-VN-118.2026",
  "public_key_pem": "-----BEGIN PUBLIC KEY-----\n…\n-----END PUBLIC KEY-----\n"
}

响应

状态码类型说明
201LabKey
application/json

The new key.

400Error
application/json

Invalid JSON, an unknown field, a bad kid or public key, or a bad X-Request-Id; or a malformed or repeated Idempotency-Key header.

401Error
application/json

No valid session, API token or legacy token.

403Error
application/json

The caller is known but refused: role not permitted, tenant not allowed (X-Tenant), origin not allowed or CSRF token missing or invalid (cookie sessions on unsafe methods).

404Error
application/json

No such lab, or a lab outside the caller's scope (a lab user's other labs).

405Error
application/json

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

409Error
application/json

The key id is taken (by any key) or reserved. Or the Idempotency-Key's first request is still running (Retry-After), or it ran but its response cannot be replayed (too large to store, or never recorded).

413Error
application/json

The request body is over 1 MiB.

422Error
application/json

The Idempotency-Key was used by this principal within 24 hours with another method, path, query or body.

500Error
application/json

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

响应头

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

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.

Idempotent-Replayed201"true"

true when the response is the stored response of an earlier request with the same Idempotency-Key.

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-Id409string

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-After409string

Seconds to wait before retrying.

X-Request-Id413string

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-Id422string

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

响应示例

响应 201 · application/json
{
  "kid": "LAB-VN-118.2026",
  "lab": "LAB-VN-118",
  "status": "active",
  "created_at": 1790000000.5,
  "revoked_at": null,
  "revoke_reason": null,
  "revoked_by": null,
  "fingerprint_sha256": "19fcfa6012e7f761a1f1e408e6bc08ce10ce6a4347be82fd3c9ddf6a9fcfe0d9",
  "fingerprint": "19fc…e0d9",
  "custody": "lab"
}
响应 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
响应 400 · application/json · unknown_field
{
  "error": "unknown field",
  "code": "unknown_field"
}
响应 400 · application/json · invalid_pem
{
  "error": "invalid public_key_pem: an EC P-256 public key as PEM SubjectPublicKeyInfo",
  "code": "invalid_public_key_pem"
}
响应 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
响应 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"
}
响应 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
响应 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
响应 404 · application/json
{
  "error": "not found: LAB-VN-118",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 409 · application/json · key_id_taken
{
  "error": "key id taken",
  "code": "key_id_taken"
}
响应 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
响应 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
响应 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
响应 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
响应 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/labs/{code}/keys/{kid}/revoke

Revoke a lab signing key

身份验证:cookie, bearer · revokeLabKey

Marks the key revoked with its reason; a revoked key cannot be revoked again (the first reason and time stay). compromise also raises one high-severity lab_key_compromised platform alert. Audited (lab_key.revoke). Allowed for platform_admin (every lab) and for a lab user signed in with a session (its own lab only; another lab answers 404 like a missing one). A lab principal without a lab (an API token) is refused 403. Step-up (#87): a signed-in session of an account with two-step sign-in must have confirmed a code from its authenticator app (or a backup code) within the last 5 minutes and its password within the last 10 minutes, else 401 mfa_step_up_required before anything is done (no audit row): confirm both with POST /v1/auth/reauth, then repeat the request. A session of an account without two-step sign-in, API tokens and API clients are served as before.

参数

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

Lab code, e.g. LAB-VN-118.

kid
必填
pathstring

Key id.

Idempotency-Key
可选
headerstring

Makes a retry of this request safe (#169). A client-chosen key, 1 to 255 visible ASCII characters (a UUID is a good choice), scoped to the caller's tenant and principal (session user, API token or legacy token). The first request with a key runs; when it answers 2xx, that response (status, body and headers) is stored and replayed for 24 hours to every request with the same key and the same method, path, query and body bytes, marked Idempotent-Replayed: true, without running the operation again or writing another audit row. The same key with another request is 422 idempotency_key_mismatch; while the first request still runs it is 409 idempotency_key_in_use with Retry-After. A request that fails before its operation commits releases the key, so it may be sent again (corrected) with the same key. An operation that committed is never run again under its key, even when its response could not be recorded (a 500 after the commit; a server stop or a database error between the commit and the record): the retry is 409 idempotency_key_in_use for up to 5 minutes, then 409 idempotency_key_used until the key expires. A malformed or repeated header is 400 invalid_idempotency_key.

请求体

KeyRevoke (必填)

媒体类型: application/json

请求示例 · application/json
{
  "reason": "rotation"
}

响应

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

The key after revocation.

400Error
application/json

Invalid JSON, a reason other than rotation or compromise, or a bad X-Request-Id; or a malformed or repeated Idempotency-Key header.

401Error
application/json

No valid session, API token or legacy token. Or a session of an account with two-step sign-in whose code was last confirmed more than 5 minutes ago, or its password more than 10 minutes ago (mfa_step_up_required, #87: confirm both with POST /v1/auth/reauth, then repeat the request; nothing was done and no audit row was written).

403Error
application/json

The caller is known but refused: role not permitted, tenant not allowed (X-Tenant), origin not allowed or CSRF token missing or invalid (cookie sessions on unsafe methods).

404Error
application/json

No such lab in the caller's scope, or no such key of the lab.

405Error
application/json

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

409Error
application/json

The key is already revoked. Or the Idempotency-Key's first request is still running (Retry-After), or it ran but its response cannot be replayed (too large to store, or never recorded).

413Error
application/json

The request body is over 1 MiB.

422Error
application/json

The Idempotency-Key was used by this principal within 24 hours with another method, path, query or body.

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.

Idempotent-Replayed200"true"

true when the response is the stored response of an earlier request with the same Idempotency-Key.

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-Id409string

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-After409string

Seconds to wait before retrying.

X-Request-Id413string

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-Id422string

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-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
{
  "kid": "LAB-VN-118.2026",
  "lab": "LAB-VN-118",
  "status": "revoked",
  "created_at": 1790000000.5,
  "revoked_at": 1790086400.5,
  "revoke_reason": "rotation",
  "revoked_by": "lab@lab.example",
  "fingerprint_sha256": "19fcfa6012e7f761a1f1e408e6bc08ce10ce6a4347be82fd3c9ddf6a9fcfe0d9",
  "fingerprint": "19fc…e0d9",
  "custody": "lab"
}
响应 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
响应 400 · application/json · invalid_reason
{
  "error": "invalid reason: rotation or compromise",
  "code": "invalid_reason"
}
响应 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
响应 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"
}
响应 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
响应 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
响应 404 · application/json
{
  "error": "not found: LAB-VN-118",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 409 · application/json · key_already_revoked
{
  "error": "key already revoked",
  "code": "key_already_revoked"
}
响应 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
响应 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
响应 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
响应 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
响应 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/{lot}/residue-certificate

A lot's residue certificate

身份验证:cookie, bearer, oauth2 · OAuth2 作用域:records_export · getLotResidueCertificate

#157: every analyte the lot's lab report tested, with its result, the limit of the lot's destination market, where that limit comes from and the verdict, for staff to hand to a buyer. The destination market (market_from) is the lot's shipment's destination once the lot is on a shipment, else the lot's own destination when it names a market, else the market of the lab report. For the report's own market each analyte keeps the limit copied onto its results when the lab report was stored; for another market the limit is that market's entry for the lot's product on the report's signed date (limits_on, Asia/Ho_Chi_Minh), else the market's default limit rule for pesticides (basis default_limit: Japan's and Korea's uniform 0.01 mg/kg, the EU's default of Regulation (EC) No 396/2005 Art. 18(1)(b), and in the United States a residue without a tolerance is not permitted). The default rule applies only to a pesticide that a source the platform has read shows the market sets no specific limit for in the lot's product; otherwise the analyte has no limit. It never applies to a contaminant such as cadmium or to auramine O. Limits are read on the report's signed date, so a limit the platform records later never judges a report signed before it takes effect. An analyte passes when every sample's result passes (a detection limit above a maximum cannot show compliance; a banned substance passes only when not detected); no_limit when the market sets none. required_analytes are the analytes the destination market's sampling rule for the lot's crop requires, missing_analytes those the lab did not test. The certificate's verdict: fail when an analyte fails, else incomplete when an analyte has no limit, a required analyte is missing or the lab key that signed the report has been revoked for compromise (report.key_revoked_for_compromise: the report then counts as unsigned, as on the public lot record, so it never earns pass), else pass; all null and empty while the lab has not reported. Never on the public record (owner decision: staff and buyers only; buyers have no account yet). An audited read (export.residue_certificate: the market, the verdict and the analyte counts), downloaded as an attachment (Content-Disposition), never cached. Allowed for tenant_admin, platform_admin acting for the tenant and auditor; operators and labs are refused; another tenant's lot answers like a missing one. An OAuth2 access token needs the records_export scope. Not part of the partner SDK clients (x-not-in-sdk): SDK 0.2.0 was released before it.

参数

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

Lot code (unique within the tenant).

响应

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

The residue certificate (ResidueCertificate).

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 (tenant_admin, platform_admin and auditor only) or tenant not allowed (X-Tenant).

404Error
application/json

No such lot for this tenant: a lot of another tenant answers exactly like a missing one.

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.

Content-Disposition200string

attachment; filename="residue-certificate-{lot}.json"

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
{
  "lot": "LO-260928-014",
  "product": "durian",
  "report": {
    "report_no": "KN-260929-0071",
    "lab": "LAB-VN-118",
    "market": "CN",
    "signed_at": 1790671200,
    "received_at": 1790671260,
    "key_custody": "lab",
    "key_revoked_for_compromise": false
  },
  "market": "CN",
  "market_from": "report",
  "limits_on": "2026-09-29",
  "verdict": "pass",
  "analytes": [
    {
      "analyte": "cadmium",
      "samples": 3,
      "outcome": "measured",
      "value": 0.018,
      "lod": null,
      "unit": "mg/kg",
      "limit": {
        "kind": "max",
        "value": 0.05,
        "unit": "mg/kg",
        "source": "GB 2762-2022 National food safety standard: maximum levels of contaminants in foods, 4.2 cadmium, fresh fruit 0.05 mg/kg (published 2022-06-30, in force 2023-06-30)",
        "basis": "market_limit"
      },
      "verdict": "pass"
    },
    {
      "analyte": "auramine_o",
      "samples": 3,
      "outcome": "not_detected",
      "value": null,
      "lod": 0.001,
      "unit": "mg/kg",
      "limit": {
        "kind": "banned",
        "value": null,
        "unit": "mg/kg",
        "source": "Auramine O is a non-edible substance in China (Ministry of Health list, 2008): no level is permitted",
        "basis": "market_limit"
      },
      "verdict": "pass"
    }
  ],
  "required_analytes": [
    "cadmium",
    "auramine_o"
  ],
  "missing_analytes": []
}
响应 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: LO-260928-014",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lab/samples

The caller lab's sample assignments

身份验证:cookie, bearer · listLabAssignments

The samplings assigned to the caller's lab across every tenant, newest first, with keyset pagination (at most 50 per page): exporter, lot, facility, test scope and the fruits to collect. Allowed for a lab user signed in with a session (its lab only); every other role, and a lab principal without a lab (an API token), is refused 403. Not audited (a read).

参数

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

next_cursor of the previous page.

limit
可选
queryinteger

Page size, 1 to 50.

响应

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

One page of assignments.

400Error
application/json

A cursor that is not one this API issued, a limit out of range, 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": 41,
      "exporter": "HTX Ngũ Hiệp",
      "lot": {
        "code": "LO-260928-014",
        "product": "durian",
        "variety": "Ri6",
        "harvest_date": "2026-09-27"
      },
      "facility": {
        "code": "VN-TGPH-021",
        "name": "Cơ sở đóng gói Tân Phú",
        "address": null,
        "province": "Tiền Giang",
        "district": "Cai Lậy"
      },
      "analytes": [
        "cadmium",
        "auramine_o"
      ],
      "sample_count": 3,
      "selected_at": 1790000000.5,
      "samples": [
        {
          "k": 1,
          "fruit": "Q-014-0017",
          "status": "selected"
        },
        {
          "k": 2,
          "fruit": "Q-014-0062",
          "status": "selected"
        },
        {
          "k": 3,
          "fruit": "Q-014-0109",
          "status": "selected"
        }
      ],
      "report": null
    }
  ],
  "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_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"
}

POST /v1/lab/samples/{id}/results

Submit the signed lab report of an assigned sampling

身份验证:cookie, bearer · submitLabReport

The assigned lab's report for one of its samplings (the id of GET /v1/lab/samples): a document signed with an active key of that lab (LabReportSubmission). The server verifies the signature against the registered key, judges every result against the market's limits (China: cadmium at most 0.05 mg/kg, GB 2762-2022; auramine O banned), and any optional origin isotope result by its region match (a mismatch fails), and stores the report once: each drawn sample becomes passed or failed, and a failing report raises a high-severity lab_result_failed alert for the lot's tenant and puts the lot on hold on its public record. Audited (lab_report.submit). Allowed only for a lab user signed in with a session, for its own lab's samplings (another lab's sampling answers 404 like a missing one); every other role, and a lab principal without a lab (an API token), is refused 403, so a tenant can never submit a result for its own lot.

参数

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

Sampling id, as GET /v1/lab/samples lists it.

Idempotency-Key
可选
headerstring

Makes a retry of this request safe (#169). A client-chosen key, 1 to 255 visible ASCII characters (a UUID is a good choice), scoped to the caller's tenant and principal (session user, API token or legacy token). The first request with a key runs; when it answers 2xx, that response (status, body and headers) is stored and replayed for 24 hours to every request with the same key and the same method, path, query and body bytes, marked Idempotent-Replayed: true, without running the operation again or writing another audit row. The same key with another request is 422 idempotency_key_mismatch; while the first request still runs it is 409 idempotency_key_in_use with Retry-After. A request that fails before its operation commits releases the key, so it may be sent again (corrected) with the same key. An operation that committed is never run again under its key, even when its response could not be recorded (a 500 after the commit; a server stop or a database error between the commit and the record): the retry is 409 idempotency_key_in_use for up to 5 minutes, then 409 idempotency_key_used until the key expires. A malformed or repeated header is 400 invalid_idempotency_key.

请求体

LabReportSubmission (必填)

媒体类型: application/json

请求示例 · application/json
{
  "v": 1,
  "lab": "LAB-VN-118",
  "sampling": 41,
  "report_no": "KN-260929-0071",
  "signed_at": "2026-09-29T15:40:00+07:00",
  "report_sha256": "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f",
  "results": [
    {
      "sample": 1,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS"
    },
    {
      "sample": 1,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS"
    },
    {
      "sample": 2,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS"
    },
    {
      "sample": 2,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS"
    },
    {
      "sample": 3,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS"
    },
    {
      "sample": 3,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS"
    }
  ],
  "sig": {
    "alg": "ES256",
    "kid": "LAB-VN-118.2026",
    "value": "oXJnReuBsgt-B5Q50XZIMc1f4ZyKrNbBmGQGqNG_AlzMknHMQA6jRzDDnLYMSR2xQ4fONFxUvflGduCSkSCgTg"
  }
}

响应

状态码类型说明
201LabReport
application/json

The stored report.

400Error
application/json

Invalid JSON, a missing or unknown member, a result outside the sampling or an incomplete report, a bad value, unit or detection limit, a bad origin result (outcome, region), a signed_at before the draw or in the future, or a bad X-Request-Id; or a malformed or repeated Idempotency-Key header.

401Error
application/json

No valid session or token, or the report is unsigned or its signature does not verify with an active key of the assigned lab (unknown or revoked key, another lab's key, altered content).

403Error
application/json

The caller is known but refused: role not permitted, tenant not allowed (X-Tenant), origin not allowed or CSRF token missing or invalid (cookie sessions on unsafe methods). SELF-2-4 (#193): also company read-only when the sampling's company is leaving CropPath or has left, whatever company the lab user belongs to; nothing is stored.

404Error
application/json

No such sampling, or one assigned to another lab.

405Error
application/json

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

409Error
application/json

The sampling already has a report (nothing is overwritten), the lab's report number is taken, or the lab is not in force. Or the Idempotency-Key's first request is still running (Retry-After), or it ran but its response cannot be replayed (too large to store, or never recorded).

413Error
application/json

The request body is over 1 MiB.

422Error
application/json

The Idempotency-Key was used by this principal within 24 hours with another method, path, query or body.

500Error
application/json

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

响应头

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

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.

Idempotent-Replayed201"true"

true when the response is the stored response of an earlier request with the same Idempotency-Key.

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-Id409string

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-After409string

Seconds to wait before retrying.

X-Request-Id413string

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-Id422string

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

响应示例

响应 201 · application/json
{
  "report_no": "KN-260929-0071",
  "lab": "LAB-VN-118",
  "kid": "LAB-VN-118.2026",
  "key_custody": "lab",
  "market": "CN",
  "signed_at": 1790671200,
  "report_sha256": "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f",
  "passed": true,
  "analytes": [
    {
      "analyte": "auramine_o",
      "passed": true
    },
    {
      "analyte": "cadmium",
      "passed": true
    }
  ],
  "results": [
    {
      "sample": 1,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "value": null,
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS",
      "limit": {
        "kind": "banned",
        "value": null,
        "unit": "mg/kg",
        "source": "Auramine O is a non-edible substance in China (Ministry of Health list, 2008): no level is permitted; GACC requires an auramine O test report with every durian shipment since 2025-01-10 (https://www.producereport.com/article/vietnamese-durian-exports-china-halted-over-missing-test-reports)"
      },
      "passed": true
    },
    {
      "sample": 1,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS",
      "limit": {
        "kind": "max",
        "value": 0.05,
        "unit": "mg/kg",
        "source": "GB 2762-2022 National food safety standard: maximum levels of contaminants in foods, 4.2 cadmium, fresh fruit 0.05 mg/kg (published 2022-06-30, in force 2023-06-30)"
      },
      "passed": true
    },
    {
      "sample": 2,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "value": null,
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS",
      "limit": {
        "kind": "banned",
        "value": null,
        "unit": "mg/kg",
        "source": "Auramine O is a non-edible substance in China (Ministry of Health list, 2008): no level is permitted; GACC requires an auramine O test report with every durian shipment since 2025-01-10 (https://www.producereport.com/article/vietnamese-durian-exports-china-halted-over-missing-test-reports)"
      },
      "passed": true
    },
    {
      "sample": 2,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS",
      "limit": {
        "kind": "max",
        "value": 0.05,
        "unit": "mg/kg",
        "source": "GB 2762-2022 National food safety standard: maximum levels of contaminants in foods, 4.2 cadmium, fresh fruit 0.05 mg/kg (published 2022-06-30, in force 2023-06-30)"
      },
      "passed": true
    },
    {
      "sample": 3,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "value": null,
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS",
      "limit": {
        "kind": "banned",
        "value": null,
        "unit": "mg/kg",
        "source": "Auramine O is a non-edible substance in China (Ministry of Health list, 2008): no level is permitted; GACC requires an auramine O test report with every durian shipment since 2025-01-10 (https://www.producereport.com/article/vietnamese-durian-exports-china-halted-over-missing-test-reports)"
      },
      "passed": true
    },
    {
      "sample": 3,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS",
      "limit": {
        "kind": "max",
        "value": 0.05,
        "unit": "mg/kg",
        "source": "GB 2762-2022 National food safety standard: maximum levels of contaminants in foods, 4.2 cadmium, fresh fruit 0.05 mg/kg (published 2022-06-30, in force 2023-06-30)"
      },
      "passed": true
    }
  ],
  "origin": [],
  "submitted_by": "lab@lab.example",
  "received_at": 1790671260.5,
  "report_pdf": null
}
响应 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
响应 400 · application/json · incomplete
{
  "error": "incomplete results: no cadmium result for sample 3 (1 missing)",
  "code": "incomplete_results"
}
响应 400 · application/json · unit
{
  "error": "invalid results[0].unit: mg/kg",
  "code": "invalid_results_0_unit"
}
响应 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
响应 401 · application/json · token
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
响应 401 · application/json · signature
{
  "error": "signature not verified: sign the report with an active key of the assigned lab",
  "code": "signature_not_verified"
}
响应 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
响应 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
响应 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
响应 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
响应 403 · application/json · company_read_only
{
  "error": "company read-only: the company is leaving or has left CropPath; its records can be read and exported but not changed",
  "code": "company_read_only"
}
响应 404 · application/json
{
  "error": "not found: 41",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 409 · application/json · reported
{
  "error": "sampling already reported",
  "code": "sampling_already_reported"
}
响应 409 · application/json · number
{
  "error": "report number taken",
  "code": "report_number_taken"
}
响应 409 · application/json · lab
{
  "error": "lab not in force: suspended, or its accreditation expired before the signed date",
  "code": "lab_not_in_force"
}
响应 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
响应 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
响应 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
响应 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
响应 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/market-limits

Market limits (maximum residue levels and bans)

身份验证:cookie, bearer, oauth2 · OAuth2 作用域:market_limit_read · listMarketLimits

Every entry by id, one page (limit, default 100, at most 200; cursor from the previous page), each with its status on today. Platform data, the same for every tenant. Allowed for every role. Not audited (a read).

参数

名称位置类型说明
limit
可选
queryinteger

1 to 200 (default 100).

cursor
可选
querystring

The previous page's next_cursor.

响应

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

One page of entries.

400Error
application/json

A bad limit or cursor, 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 (a principal without a role), 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": 1,
      "market": "CN",
      "product": "durian",
      "analyte": "cadmium",
      "kind": "max",
      "value": 0.05,
      "unit": "mg/kg",
      "valid_from": "2023-06-30",
      "source": "GB 2762-2022 National food safety standard: maximum levels of contaminants in foods, 4.2 cadmium, fresh fruit 0.05 mg/kg (published 2022-06-30, in force 2023-06-30)",
      "created_at": 1790000000.5,
      "created_by": "migration",
      "status": "in_force"
    },
    {
      "id": 2,
      "market": "CN",
      "product": "durian",
      "analyte": "auramine_o",
      "kind": "banned",
      "value": null,
      "unit": "mg/kg",
      "valid_from": "2025-01-10",
      "source": "Auramine O is a non-edible substance in China (Ministry of Health list, 2008): no level is permitted; GACC requires an auramine O test report with every durian shipment since 2025-01-10 (https://www.producereport.com/article/vietnamese-durian-exports-china-halted-over-missing-test-reports)",
      "created_at": 1790000000.5,
      "created_by": "migration",
      "status": "in_force"
    }
  ],
  "today": "2026-09-30",
  "next_cursor": null
}
响应 400 · application/json · limit
{
  "error": "bad limit",
  "code": "bad_limit"
}
响应 400 · application/json · cursor
{
  "error": "bad cursor",
  "code": "bad_cursor"
}
响应 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/lab/samples/{id}

One of the lab's assigned samplings, with its report

身份验证:cookie, bearer · getLabAssignment

A7 (#73): the lab portal's sampling page. One sampling assigned to the caller's lab, with its samples, its full report once stored (LabReport, with the custody of the key that signed it) and the lab's active server-held portal key. Allowed only for a lab user signed in with a session; another lab's sampling answers 404 like a missing one; every other role, and a lab principal without a lab (an API token), is refused 403.

参数

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

Sampling id, as GET /v1/lab/samples lists it.

响应

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

The sampling.

400Error
application/json

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

404Error
application/json

No such sampling, or one assigned to another lab.

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": 41,
  "exporter": "HTX Ngũ Hiệp",
  "lot": {
    "code": "LO-260928-014",
    "product": "durian",
    "variety": "Ri6",
    "harvest_date": "2026-09-27"
  },
  "facility": {
    "code": "VN-TGPH-021",
    "name": "Cơ sở đóng gói Tân Phú",
    "address": null,
    "province": "Tiền Giang",
    "district": "Cai Lậy"
  },
  "analytes": [
    "cadmium",
    "auramine_o"
  ],
  "sample_count": 3,
  "selected_at": 1790000000.5,
  "samples": [
    {
      "k": 1,
      "fruit": "Q-014-0017",
      "status": "selected"
    },
    {
      "k": 2,
      "fruit": "Q-014-0062",
      "status": "selected"
    },
    {
      "k": 3,
      "fruit": "Q-014-0109",
      "status": "selected"
    }
  ],
  "report": null,
  "portal_key": {
    "kid": "LAB-VN-118.portal"
  }
}
响应 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"
}
响应 404 · application/json
{
  "error": "not found: 41",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/lab/samples/{id}/entry

Enter the lab results of an assigned sampling in the portal

身份验证:cookie, bearer · enterLabReport

A7 (#73): the lab portal's result form for one of the lab's samplings. The server builds the report document from the entry (LabPortalEntry: version 1, the lab, the sampling, the server's time as signed_at), signs it with the lab's active server-held key (custody server, generated by POST /v1/labs/{code}/portal-key) and stores it exactly as POST /v1/lab/samples/{id}/results stores an uploaded signed report (verification, market limits, sample statuses, the lab_result_failed alert and lab hold). The report's key_custody is server: the public record and the credential state that the platform, not the lab, holds the key, and the lab step never counts the result as signed by the accredited lab (ADR 0001: at most Cross-checked). Audited (lab_report.enter). Allowed only for a lab user signed in with a session, for its own lab's samplings (another lab's sampling answers 404 like a missing one); every other role, and a lab principal without a lab (an API token), is refused 403.

参数

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

Sampling id, as GET /v1/lab/samples lists it.

Idempotency-Key
可选
headerstring

Makes a retry of this request safe (#169). A client-chosen key, 1 to 255 visible ASCII characters (a UUID is a good choice), scoped to the caller's tenant and principal (session user, API token or legacy token). The first request with a key runs; when it answers 2xx, that response (status, body and headers) is stored and replayed for 24 hours to every request with the same key and the same method, path, query and body bytes, marked Idempotent-Replayed: true, without running the operation again or writing another audit row. The same key with another request is 422 idempotency_key_mismatch; while the first request still runs it is 409 idempotency_key_in_use with Retry-After. A request that fails before its operation commits releases the key, so it may be sent again (corrected) with the same key. An operation that committed is never run again under its key, even when its response could not be recorded (a 500 after the commit; a server stop or a database error between the commit and the record): the retry is 409 idempotency_key_in_use for up to 5 minutes, then 409 idempotency_key_used until the key expires. A malformed or repeated header is 400 invalid_idempotency_key.

请求体

LabPortalEntry (必填)

媒体类型: application/json

请求示例 · application/json
{
  "report_no": "KN-260929-0071",
  "report_sha256": "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f",
  "results": [
    {
      "sample": 1,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS"
    },
    {
      "sample": 1,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS"
    },
    {
      "sample": 2,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS"
    },
    {
      "sample": 2,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS"
    },
    {
      "sample": 3,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS"
    },
    {
      "sample": 3,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS"
    }
  ]
}

响应

状态码类型说明
201LabReport
application/json

The stored report.

400Error
application/json

Invalid JSON, a missing or unknown member, a result outside the sampling or an incomplete report, a bad value, unit or detection limit, a bad origin result (outcome, region), a signed_at before the draw or in the future, or a bad X-Request-Id; or a malformed or repeated Idempotency-Key header.

401Error
application/json

No valid session, API token or legacy token.

403Error
application/json

The caller is known but refused: role not permitted, tenant not allowed (X-Tenant), origin not allowed or CSRF token missing or invalid (cookie sessions on unsafe methods). SELF-2-4 (#193): also company read-only when the sampling's company is leaving CropPath or has left, whatever company the lab user belongs to; nothing is stored.

404Error
application/json

No such sampling, or one assigned to another lab.

405Error
application/json

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

409Error
application/json

The lab holds no active server-held key, the sampling already has a report (nothing is overwritten), the lab's report number is taken, or the lab is not in force. Or the Idempotency-Key's first request is still running (Retry-After), or it ran but its response cannot be replayed (too large to store, or never recorded).

413Error
application/json

The request body is over 1 MiB.

422Error
application/json

The Idempotency-Key was used by this principal within 24 hours with another method, path, query or body.

500Error
application/json

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

503Error
application/json

The server cannot read the lab's server-held key: no key-encryption key is configured (AGRITRACE_ISSUER_KEK) or its file does not decrypt; nothing changed.

响应头

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

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.

Idempotent-Replayed201"true"

true when the response is the stored response of an earlier request with the same Idempotency-Key.

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-Id409string

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-After409string

Seconds to wait before retrying.

X-Request-Id413string

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-Id422string

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

响应示例

响应 201 · application/json
{
  "report_no": "KN-260929-0071",
  "lab": "LAB-VN-118",
  "kid": "LAB-VN-118.portal",
  "key_custody": "server",
  "market": "CN",
  "signed_at": 1790671200,
  "report_sha256": "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f",
  "passed": true,
  "analytes": [
    {
      "analyte": "auramine_o",
      "passed": true
    },
    {
      "analyte": "cadmium",
      "passed": true
    }
  ],
  "results": [
    {
      "sample": 1,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "value": null,
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS",
      "limit": {
        "kind": "banned",
        "value": null,
        "unit": "mg/kg",
        "source": "Auramine O is a non-edible substance in China (Ministry of Health list, 2008): no level is permitted; GACC requires an auramine O test report with every durian shipment since 2025-01-10 (https://www.producereport.com/article/vietnamese-durian-exports-china-halted-over-missing-test-reports)"
      },
      "passed": true
    },
    {
      "sample": 1,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS",
      "limit": {
        "kind": "max",
        "value": 0.05,
        "unit": "mg/kg",
        "source": "GB 2762-2022 National food safety standard: maximum levels of contaminants in foods, 4.2 cadmium, fresh fruit 0.05 mg/kg (published 2022-06-30, in force 2023-06-30)"
      },
      "passed": true
    },
    {
      "sample": 2,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "value": null,
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS",
      "limit": {
        "kind": "banned",
        "value": null,
        "unit": "mg/kg",
        "source": "Auramine O is a non-edible substance in China (Ministry of Health list, 2008): no level is permitted; GACC requires an auramine O test report with every durian shipment since 2025-01-10 (https://www.producereport.com/article/vietnamese-durian-exports-china-halted-over-missing-test-reports)"
      },
      "passed": true
    },
    {
      "sample": 2,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS",
      "limit": {
        "kind": "max",
        "value": 0.05,
        "unit": "mg/kg",
        "source": "GB 2762-2022 National food safety standard: maximum levels of contaminants in foods, 4.2 cadmium, fresh fruit 0.05 mg/kg (published 2022-06-30, in force 2023-06-30)"
      },
      "passed": true
    },
    {
      "sample": 3,
      "analyte": "auramine_o",
      "outcome": "not_detected",
      "value": null,
      "unit": "mg/kg",
      "lod": 0.001,
      "method": "LC-MS/MS",
      "limit": {
        "kind": "banned",
        "value": null,
        "unit": "mg/kg",
        "source": "Auramine O is a non-edible substance in China (Ministry of Health list, 2008): no level is permitted; GACC requires an auramine O test report with every durian shipment since 2025-01-10 (https://www.producereport.com/article/vietnamese-durian-exports-china-halted-over-missing-test-reports)"
      },
      "passed": true
    },
    {
      "sample": 3,
      "analyte": "cadmium",
      "outcome": "measured",
      "value": 0.018,
      "unit": "mg/kg",
      "lod": 0.002,
      "method": "ICP-MS",
      "limit": {
        "kind": "max",
        "value": 0.05,
        "unit": "mg/kg",
        "source": "GB 2762-2022 National food safety standard: maximum levels of contaminants in foods, 4.2 cadmium, fresh fruit 0.05 mg/kg (published 2022-06-30, in force 2023-06-30)"
      },
      "passed": true
    }
  ],
  "origin": [],
  "submitted_by": "lab@lab.example",
  "received_at": 1790671260.5,
  "report_pdf": null
}
响应 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
响应 400 · application/json · incomplete
{
  "error": "incomplete results: no cadmium result for sample 3 (1 missing)",
  "code": "incomplete_results"
}
响应 400 · application/json · unit
{
  "error": "invalid results[0].unit: mg/kg",
  "code": "invalid_results_0_unit"
}
响应 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
响应 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
响应 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"
}
响应 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
响应 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
响应 403 · application/json · company_read_only
{
  "error": "company read-only: the company is leaving or has left CropPath; its records can be read and exported but not changed",
  "code": "company_read_only"
}
响应 404 · application/json
{
  "error": "not found: 41",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 409 · application/json · reported
{
  "error": "sampling already reported",
  "code": "sampling_already_reported"
}
响应 409 · application/json · number
{
  "error": "report number taken",
  "code": "report_number_taken"
}
响应 409 · application/json · lab
{
  "error": "lab not in force: suspended, or its accreditation expired before the signed date",
  "code": "lab_not_in_force"
}
响应 409 · application/json · no_portal_key
{
  "error": "no portal key: the lab holds no active server-held key to sign portal entries",
  "code": "no_portal_key"
}
响应 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
响应 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
响应 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
响应 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
响应 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}
响应 503 · application/json
{
  "error": "issuer keys unavailable: AGRITRACE_ISSUER_KEK is not configured",
  "code": "issuer_keys_unavailable"
}

PUT /v1/lab/samples/{id}/report-pdf

Store the PDF original of a lab report

身份验证:cookie, bearer · attachLabReportPdf

A7 (#73, owner decision 4): the PDF original of the report of one of the lab's samplings, sent after the report was stored by either POST /v1/lab/samples/{id}/results or POST /v1/lab/samples/{id}/entry. The body is the PDF itself. Content-Type must be application/pdf (parameters ignored) and the bytes must start with %PDF-. The body is at most 1 MiB and must hash to the report's report_sha256. The file is stored once as a staff-only attachment owned by the sampling's tenant: only its tenant-wide staff read the bytes with GET /v1/attachments/{sha256}, a facility-scoped grant does not. The report links it as report_pdf. Nothing public changes: the public record keeps lab.report_url null and never names the file. It changes no verdict and no trust tier. A repeat of a stored PDF answers 200 and changes nothing, but its bytes are still checked against the report. Audited (lab_report.attach_pdf: the hash, media type and size, never the bytes). Allowed only for a lab user, for its own lab's samplings (another lab's sampling answers 404 like a missing one); every other role, and a lab principal without a lab (an API token), is refused 403.

参数

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

Sampling id, as GET /v1/lab/samples lists it.

请求体

string (必填)

媒体类型: application/pdf

请求示例 · application/pdf
%PDF-1.7 ... (binary PDF bytes)

响应

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

The sampling's tenant already holds this PDF; nothing changed.

201AttachmentStored
application/json

Stored and linked from the report as report_pdf.

400Error
application/json

A missing or malformed Content-Length, 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, tenant not allowed (X-Tenant), origin not allowed or CSRF token missing or invalid (cookie sessions on unsafe methods). SELF-2-4 (#193): also company read-only when the sampling's company is leaving CropPath or has left, whatever company the lab user belongs to; nothing is stored.

404Error
application/json

No such sampling, or one assigned to another lab.

405Error
application/json

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

409Error
application/json

The sampling has no report yet: the PDF follows the report.

413Error
application/json

The request body is over 1 MiB.

415Error
application/json

Not declared as application/pdf, or bytes that do not start with the PDF signature %PDF-; nothing is stored.

422Error
application/json

The body does not hash to the report's report_sha256: it is not the file the report names; nothing is stored.

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-Id201string

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-Id409string

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-Id413string

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-Id415string

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-Id422string

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-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
{
  "sha256": "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f",
  "media_type": "application/pdf",
  "size": 182344
}
响应 201 · application/json
{
  "sha256": "5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f5f",
  "media_type": "application/pdf",
  "size": 182344
}
响应 400 · application/json · bad_content_length
{
  "error": "bad content length",
  "code": "bad_content_length"
}
响应 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"
}
响应 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
响应 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
响应 403 · application/json · company_read_only
{
  "error": "company read-only: the company is leaving or has left CropPath; its records can be read and exported but not changed",
  "code": "company_read_only"
}
响应 404 · application/json
{
  "error": "not found: 41",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 409 · application/json
{
  "error": "no report yet: store the sampling's report before its PDF",
  "code": "no_report_yet"
}
响应 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
响应 415 · application/json · unsupported_media_type
{
  "error": "unsupported media type",
  "code": "unsupported_media_type"
}
响应 415 · application/json · content_does_not_match_the_media_type
{
  "error": "content does not match the media type",
  "code": "content_does_not_match_the_media_type"
}
响应 422 · application/json
{
  "error": "report pdf mismatch: the file does not hash to the report's report_sha256",
  "code": "report_pdf_mismatch"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/labs/{code}/approvals

A lab's market approvals

身份验证:cookie, bearer · listLabApprovals

#154: every market approval of the lab (at most 100, one page), each with whether it is in force today. Allowed for platform_admin (every lab) and for a lab user signed in with a session (its own lab only; another lab answers 404 like a missing one). A lab principal without a lab (an API token) is refused 403. Not audited (a read).

参数

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

Lab code, e.g. LAB-VN-118.

响应

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

The lab's approvals.

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 lab, or a lab outside the caller's scope (a lab user's other labs).

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
{
  "items": [
    {
      "id": 7,
      "lab": "LAB-VN-118",
      "market": "CN",
      "approving_body": "Plant Protection Department (MAE)",
      "reference": "List of approved labs, 2026-08-07, No. 17",
      "analytes": [
        "auramine_o",
        "cadmium"
      ],
      "valid_from": "2026-08-07",
      "valid_to": "2027-08-06",
      "source_url": "https://example.org/approved-labs-2026",
      "evidence_sha256": "9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f",
      "status": "active",
      "in_force": true,
      "created_at": 1790000000.5,
      "created_by": "admin@platform.example",
      "updated_at": 1790000000.5,
      "updated_by": "admin@platform.example"
    }
  ]
}
响应 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: LAB-VN-118",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lab/home

Read the lab portal's home

身份验证:cookie · getLabHome

仅限登录会话——API 令牌和 OAuth 客户端不可调用

#286. For the caller's lab: whether it can sign (its status, accreditation, market approvals and keys) and its work, among its newest 500 samplings across every exporter: the samplings waiting for results, oldest first, with how many were drawn more than target_hours (48) ago; the reports stored without their PDF original; the reports stored in the last 7 days and how many failed. Never another lab's samplings. Computed at most every 30 seconds per lab: the server serves one answer for max_age_s seconds after generated_at. Read-only and not audited (a read). no-store. Allowed for a lab user through a signed-in session only (its lab only): an API token, an API client or the legacy token is refused (403), and so is every other role. Not part of the partner SDK clients (x-not-in-sdk): an operation of the lab portal's home.

响应

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

The lab's home.

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 (only a lab user of a lab, through a signed-in session), tenant not allowed (X-Tenant), two-factor required.

404Error
application/json

The caller's lab is not in the registry.

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.

Cache-Control200string

no-store.

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
{
  "lab": {
    "code": "LAB-VN-118",
    "name": "Phòng kiểm nghiệm 118",
    "status": "active",
    "accreditation": "VILAS 118",
    "valid_to": "2027-03-31",
    "approvals": [
      {
        "market": "CN",
        "status": "active",
        "valid_to": "2027-12-31"
      }
    ],
    "keys": {
      "lab_held": 1,
      "server_held": true
    }
  },
  "generated_at": "2026-10-18T02:12:40Z",
  "max_age_s": 30,
  "window": {
    "samplings": 500,
    "full": false
  },
  "target_hours": 48,
  "sections": {
    "waiting": {
      "state": "ok",
      "count": 3,
      "past_target": 1,
      "items": [
        {
          "id": 71,
          "lot": "LO-260927-009",
          "exporter": "HTX Đắk Lắk",
          "sample_count": 3,
          "analytes": [
            "cadmium",
            "auramine_o"
          ],
          "selected_at": "2026-10-16T03:00:00Z"
        }
      ]
    },
    "pdf_missing": {
      "state": "ok",
      "count": 1,
      "items": [
        {
          "id": 68,
          "report_no": "KN-261015-0031",
          "received_at": "2026-10-15T08:40:00Z"
        }
      ]
    },
    "sent": {
      "state": "ok",
      "count_7d": 4,
      "failed_7d": 0,
      "items": [
        {
          "id": 69,
          "lot": "LO-260925-004",
          "report_no": "KN-261016-0040",
          "passed": true,
          "received_at": "2026-10-16T07:10:00Z"
        }
      ]
    }
  }
}
响应 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"
}
响应 403 · application/json · two_factor
{
  "error": "two-factor required: set up two-step sign-in for this account",
  "code": "two_factor_required"
}
响应 404 · application/json
{
  "error": "not found: lab",
  "code": "not_found"
}
响应 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
响应 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}