CropPath cho nhà phát triển

Tài liệu API

lots

36 thao tác

GET /v1/fruits/{code}

One fruit record

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · getFruit

A fruit of the caller's tenant by its code. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the fruits of its facilities' lots). The measurement fields come from the inspect envelopes bound to the fruit (knock, sensory override, scale); grade and eating window from the grading rules (see /v1/grading-rules).

Tham số

TênVị tríKiểuMô tả
code
bắt buộc
pathstring

Fruit code (unique within the tenant).

Phản hồi

Mã trạng tháiKiểuMô tả
200Fruit
application/json

The fruit.

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 fruit for this tenant: a fruit of another tenant, or of a lot outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "tenant": "coop-dl",
  "code": "Q-014-0129",
  "n": 129,
  "public_id": "5f0c9a1e7b2d4c3a8e6f1b0d9c7a2e4f",
  "lot": "LO-260928-014",
  "session": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "line": "A2",
  "operator": "user-7",
  "status": "recorded",
  "labels_printed_at": 1790000000.5,
  "created_at": 1790000000.5,
  "updated_at": 1790560561.2,
  "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7",
  "level": 3,
  "level_pred": 3,
  "maturity_class": "mature",
  "confidence": 0.91,
  "model": "sf100-m3",
  "measured_at": 1790560560,
  "weight_kg": 2.84,
  "level_sensory": null,
  "override": false,
  "pending_review": false,
  "grade": "A",
  "eating_window": {
    "start_days": 3,
    "end_days": 4,
    "from_date": "2026-10-01",
    "to_date": "2026-10-02",
    "band": "ambient",
    "warning": null
  },
  "record_tier": "device_recorded",
  "knock_envelope_id": "0b9c2f4e-7d1a-4c3e-9f8b-2a6d5e1c7b30",
  "scale_envelope_id": "6e3a1d9c-2b7f-4e8a-b5c4-9d0f1e2a3b47",
  "override_envelope_id": null
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: Q-014-0129",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/fruits/{code}/actions

Operator action on a fruit: accept, re-measure, reject or sensory override

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: fruit_action · actOnFruit

The operator console's actions on one fruit record (man1: sensory confirmation keys 1-4, accept into the lot, re-measure, reject). accept (recorded or overridden fruit) sets accepted_at, the status is unchanged; accepting again keeps the first time; it is 409 pending_review while the fruit's measurement is in review, and any later change of the bound measurement (a bind, a supersede, a review rejection) clears accepted_at. override (recorded or overridden) sets the sensory level and regrades with the tenant's grading rules: status overridden, effective level = the sensory level, record tier self_declared. reject (awaiting_device, recorded or overridden) sets status rejected and grade reject, which excludes the fruit from export counts. remeasure (recorded, overridden or rejected, or awaiting_device once the fruit was re-measured, so a refused round can be retried) moves the current measurement into the fruit's history (round n, replaced by round n + 1), returns the fruit to awaiting_device, and sends set_session {lot, fruit, line[, operator], round} again to the devices of the fruit's session while that session is open (otherwise each device is reported skipped, reason session_not_open); round is the new measurement_round as a string, which the device signs into the context of every later envelope. Envelopes of the superseded round never bind again: a round stamp other than the fruit's measurement_round is refused and an equal one binds, with no clock involved; an envelope without a stamp is quarantined for review (reason unverified_round) and binds only when the server received it after the re-measure and, when the same device has an accepted envelope in the superseded round, its event time is later than that one's (server and device clocks are never compared). Any other combination is 409 invalid transition; any action on a fruit whose lot is past open is 409 lot closed; any action on a fruit of a sampled lot (POST /v1/lots/{lot}/samples) is 409 lot sampled, since the sampling fixed the lot's export population; a closed session does not block an action. Idempotent per tenant and idempotency_key: replaying a key with the same fruit, type, level and reason returns 200 with the stored result and changes nothing (even if the fruit or lot changed since); the same key with anything else is 409. Only successful actions are stored. The reason is stored with the action and never returned or audited. Audited (fruit.action, replays included). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only the fruits of its facilities' lots); auditor and lab are refused.

Tham số

TênVị tríKiểuMô tả
code
bắt buộc
pathstring

Fruit code (unique within the tenant).

Idempotency-Key
không bắt buộc
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.

Nội dung yêu cầu

FruitActionRequest (bắt buộc)

Kiểu nội dung: application/json

Ví dụ yêu cầu · application/json · accept
{
  "type": "accept",
  "idempotency_key": "6f1c2a9e-4b7d-4e3a-9c8f-1d2e3f4a5b6c",
  "client_ts": "2026-09-28T08:57:02+07:00"
}
Ví dụ yêu cầu · application/json · override
{
  "type": "override",
  "level": 2,
  "idempotency_key": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d",
  "client_ts": "2026-09-28T08:57:02+07:00"
}
Ví dụ yêu cầu · application/json · reject
{
  "type": "reject",
  "reason": "cracked husk",
  "idempotency_key": "9c8b7a6f-5e4d-4c3b-8a29-1f0e9d8c7b6a",
  "client_ts": "2026-09-28T08:57:02+07:00"
}
Ví dụ yêu cầu · application/json · remeasure
{
  "type": "remeasure",
  "idempotency_key": "2b3c4d5e-6f70-4a81-9b2c-3d4e5f607182",
  "client_ts": "2026-09-28T08:57:02+07:00"
}

Phản hồi

Mã trạng tháiKiểuMô tả
200FruitActionResult
application/json

The action applied, or the stored result of an earlier request with the same key.

400Error
application/json

Invalid JSON, a body that is not an object, an unknown field, a bad type, level, reason, idempotency_key or client_ts, 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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such fruit for this tenant: a fruit of another tenant, or of a lot outside an operator's facilities, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The fruit's lot is past open or was sampled, the action does not apply to the fruit's state, an accept while the fruit's measurement is in review, or the idempotency key was already used for another request. 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json · accept
{
  "action": {
    "id": 41,
    "type": "accept",
    "level": null,
    "client_ts": "2026-09-28T08:57:02+07:00",
    "created_at": 1790560600
  },
  "fruit": {
    "tenant": "coop-dl",
    "code": "Q-014-0129",
    "n": 129,
    "public_id": "5f0c9a1e7b2d4c3a8e6f1b0d9c7a2e4f",
    "lot": "LO-260928-014",
    "session": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
    "line": "A2",
    "operator": "user-7",
    "status": "recorded",
    "labels_printed_at": 1790000000.5,
    "created_at": 1790000000.5,
    "updated_at": 1790560600,
    "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7",
    "level": 3,
    "level_pred": 3,
    "maturity_class": "mature",
    "confidence": 0.91,
    "model": "sf100-m3",
    "measured_at": 1790560560,
    "weight_kg": 2.84,
    "level_sensory": null,
    "override": false,
    "pending_review": false,
    "grade": "A",
    "eating_window": {
      "start_days": 3,
      "end_days": 4,
      "from_date": "2026-10-01",
      "to_date": "2026-10-02",
      "band": "ambient",
      "warning": null
    },
    "record_tier": "device_recorded",
    "knock_envelope_id": "0b9c2f4e-7d1a-4c3e-9f8b-2a6d5e1c7b30",
    "scale_envelope_id": "6e3a1d9c-2b7f-4e8a-b5c4-9d0f1e2a3b47",
    "override_envelope_id": null
  },
  "accepted_at": 1790560600,
  "measurement_round": 0,
  "commands": []
}
Phản hồi 200 · application/json · override
{
  "action": {
    "id": 41,
    "type": "override",
    "level": 2,
    "client_ts": "2026-09-28T08:57:02+07:00",
    "created_at": 1790560600
  },
  "fruit": {
    "tenant": "coop-dl",
    "code": "Q-014-0129",
    "n": 129,
    "public_id": "5f0c9a1e7b2d4c3a8e6f1b0d9c7a2e4f",
    "lot": "LO-260928-014",
    "session": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
    "line": "A2",
    "operator": "user-7",
    "status": "overridden",
    "labels_printed_at": 1790000000.5,
    "created_at": 1790000000.5,
    "updated_at": 1790560600,
    "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7",
    "level": 2,
    "level_pred": 3,
    "maturity_class": "mature",
    "confidence": 0.91,
    "model": "sf100-m3",
    "measured_at": 1790560560,
    "weight_kg": 2.84,
    "level_sensory": 2,
    "override": true,
    "pending_review": false,
    "grade": "B",
    "eating_window": {
      "start_days": 4,
      "end_days": 6,
      "from_date": "2026-10-02",
      "to_date": "2026-10-04",
      "band": "ambient",
      "warning": null
    },
    "record_tier": "self_declared",
    "knock_envelope_id": "0b9c2f4e-7d1a-4c3e-9f8b-2a6d5e1c7b30",
    "scale_envelope_id": "6e3a1d9c-2b7f-4e8a-b5c4-9d0f1e2a3b47",
    "override_envelope_id": null
  },
  "accepted_at": null,
  "measurement_round": 0,
  "commands": []
}
Phản hồi 200 · application/json · reject
{
  "action": {
    "id": 41,
    "type": "reject",
    "level": null,
    "client_ts": "2026-09-28T08:57:02+07:00",
    "created_at": 1790560600
  },
  "fruit": {
    "tenant": "coop-dl",
    "code": "Q-014-0129",
    "n": 129,
    "public_id": "5f0c9a1e7b2d4c3a8e6f1b0d9c7a2e4f",
    "lot": "LO-260928-014",
    "session": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
    "line": "A2",
    "operator": "user-7",
    "status": "rejected",
    "labels_printed_at": 1790000000.5,
    "created_at": 1790000000.5,
    "updated_at": 1790560600,
    "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7",
    "level": 3,
    "level_pred": 3,
    "maturity_class": "mature",
    "confidence": 0.91,
    "model": "sf100-m3",
    "measured_at": 1790560560,
    "weight_kg": 2.84,
    "level_sensory": null,
    "override": false,
    "pending_review": false,
    "grade": "reject",
    "eating_window": {
      "start_days": 3,
      "end_days": 4,
      "from_date": "2026-10-01",
      "to_date": "2026-10-02",
      "band": "ambient",
      "warning": null
    },
    "record_tier": "self_declared",
    "knock_envelope_id": "0b9c2f4e-7d1a-4c3e-9f8b-2a6d5e1c7b30",
    "scale_envelope_id": "6e3a1d9c-2b7f-4e8a-b5c4-9d0f1e2a3b47",
    "override_envelope_id": null
  },
  "accepted_at": null,
  "measurement_round": 0,
  "commands": []
}
Phản hồi 200 · application/json · remeasure
{
  "action": {
    "id": 41,
    "type": "remeasure",
    "level": null,
    "client_ts": "2026-09-28T08:57:02+07:00",
    "created_at": 1790560600
  },
  "fruit": {
    "tenant": "coop-dl",
    "code": "Q-014-0129",
    "n": 129,
    "public_id": "5f0c9a1e7b2d4c3a8e6f1b0d9c7a2e4f",
    "lot": "LO-260928-014",
    "session": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
    "line": "A2",
    "operator": "user-7",
    "status": "awaiting_device",
    "labels_printed_at": 1790000000.5,
    "created_at": 1790000000.5,
    "updated_at": 1790560600,
    "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7",
    "level": null,
    "level_pred": null,
    "maturity_class": null,
    "confidence": null,
    "model": null,
    "measured_at": null,
    "weight_kg": null,
    "level_sensory": null,
    "override": false,
    "pending_review": false,
    "grade": null,
    "eating_window": null,
    "record_tier": null,
    "knock_envelope_id": null,
    "scale_envelope_id": null,
    "override_envelope_id": null
  },
  "accepted_at": null,
  "measurement_round": 1,
  "commands": [
    {
      "device_id": "knk-1",
      "command_id": "9d2e7f40-1c3b-4a5e-8f6d-0b7c2a9e4d18",
      "status": "sent",
      "reason": null
    },
    {
      "device_id": "scale-1",
      "command_id": "1a6b3c8d-2e4f-4a7b-9c0d-5e8f1a2b3c4d",
      "status": "sent",
      "reason": null
    }
  ]
}
Phản hồi 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
Phản hồi 400 · application/json · not_an_object
{
  "error": "expected a JSON object",
  "code": "expected_a_json_object"
}
Phản hồi 400 · application/json · unknown_field
{
  "error": "unknown field",
  "code": "unknown_field"
}
Phản hồi 400 · application/json · type
{
  "error": "invalid type: one of accept, remeasure, reject, override",
  "code": "invalid_type"
}
Phản hồi 400 · application/json · level
{
  "error": "invalid level: an integer from 1 to 4",
  "code": "invalid_level"
}
Phản hồi 400 · application/json · level_not_allowed
{
  "error": "invalid level: only an override takes a level",
  "code": "invalid_level"
}
Phản hồi 400 · application/json · reason
{
  "error": "invalid reason: a string of 1 to 200 characters, or null",
  "code": "invalid_reason"
}
Phản hồi 400 · application/json · idempotency_key
{
  "error": "invalid idempotency_key: 16 to 64 letters, digits, '-' or '_'",
  "code": "invalid_idempotency_key"
}
Phản hồi 400 · application/json · client_ts
{
  "error": "invalid client_ts: an ISO 8601 date-time with a zone offset",
  "code": "invalid_client_ts"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: Q-014-0129",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · lot_closed
{
  "error": "lot closed: lot is closed",
  "code": "lot_closed"
}
Phản hồi 409 · application/json · invalid_transition
{
  "error": "invalid transition: awaiting_device to accept",
  "code": "invalid_transition"
}
Phản hồi 409 · application/json · pending_review
{
  "error": "pending review: the fruit's measurement is in review",
  "code": "pending_review"
}
Phản hồi 409 · application/json · key_reused
{
  "error": "idempotency key reused",
  "code": "idempotency_key_reused"
}
Phản hồi 409 · application/json · lot_sampled
{
  "error": "lot sampled: its export population is final",
  "code": "lot_sampled"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/grading-rules

Grading rules of the caller's tenant

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: grading_rule_read · listGradingRules

The tenant's grading rules, one per variety, by variety with keyset pagination. A variety without rules (and a lot without a variety) is graded with the platform default (see GradingRules). Allowed for platform_admin, tenant_admin and auditor; operators and lab are refused. Each page also carries platform_default, the rules in force for a variety without its own.

Tham số

TênVị tríKiểuMô tả
cursor
không bắt buộc
querystring

next_cursor of the previous page.

limit
không bắt buộc
queryinteger

Page size, 1 to 200.

Phản hồi

Mã trạng tháiKiểuMô tả
200GradingRulePage
application/json

One page of grading rules.

400Error
application/json

A cursor this API did not issue, a limit outside 1 to 200, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "items": [
    {
      "id": 3,
      "tenant": "coop-dl",
      "variety": "Ri6",
      "rules": {
        "a_levels": [
          2,
          3
        ],
        "reject_levels": [
          1,
          4
        ],
        "a_weight_kg": [
          [
            2,
            5
          ]
        ],
        "a_min_confidence": 0.8,
        "eating_window": [
          {
            "band": "ambient",
            "end_days": 7,
            "level": 1,
            "max_days": 30,
            "min_days": 0,
            "start_days": 5,
            "warning": "immature"
          },
          {
            "band": "ambient",
            "end_days": 6,
            "level": 2,
            "max_days": 1,
            "min_days": 0,
            "start_days": 4,
            "warning": null
          },
          {
            "band": "ambient",
            "end_days": 4,
            "level": 2,
            "max_days": 3,
            "min_days": 2,
            "start_days": 3,
            "warning": null
          },
          {
            "band": "ambient",
            "end_days": 2,
            "level": 2,
            "max_days": 30,
            "min_days": 4,
            "start_days": 1,
            "warning": "eat_soon"
          },
          {
            "band": "ambient",
            "end_days": 4,
            "level": 3,
            "max_days": 1,
            "min_days": 0,
            "start_days": 3,
            "warning": null
          },
          {
            "band": "ambient",
            "end_days": 3,
            "level": 3,
            "max_days": 3,
            "min_days": 2,
            "start_days": 2,
            "warning": null
          },
          {
            "band": "ambient",
            "end_days": 1,
            "level": 3,
            "max_days": 30,
            "min_days": 4,
            "start_days": 0,
            "warning": "eat_soon"
          },
          {
            "band": "ambient",
            "end_days": 1,
            "level": 4,
            "max_days": 30,
            "min_days": 0,
            "start_days": 0,
            "warning": "overripe"
          },
          {
            "band": "14-18C",
            "end_days": 10,
            "level": 1,
            "max_days": 30,
            "min_days": 0,
            "start_days": 7,
            "warning": "immature"
          },
          {
            "band": "14-18C",
            "end_days": 8,
            "level": 2,
            "max_days": 30,
            "min_days": 0,
            "start_days": 5,
            "warning": null
          },
          {
            "band": "14-18C",
            "end_days": 6,
            "level": 3,
            "max_days": 30,
            "min_days": 0,
            "start_days": 4,
            "warning": null
          },
          {
            "band": "14-18C",
            "end_days": 2,
            "level": 4,
            "max_days": 30,
            "min_days": 0,
            "start_days": 0,
            "warning": "overripe"
          },
          {
            "band": "10-13C",
            "end_days": 12,
            "level": 1,
            "max_days": 30,
            "min_days": 0,
            "start_days": 9,
            "warning": "immature"
          },
          {
            "band": "10-13C",
            "end_days": 10,
            "level": 2,
            "max_days": 30,
            "min_days": 0,
            "start_days": 7,
            "warning": null
          },
          {
            "band": "10-13C",
            "end_days": 8,
            "level": 3,
            "max_days": 30,
            "min_days": 0,
            "start_days": 5,
            "warning": null
          },
          {
            "band": "10-13C",
            "end_days": 2,
            "level": 4,
            "max_days": 30,
            "min_days": 0,
            "start_days": 0,
            "warning": "overripe"
          }
        ]
      },
      "updated_at": 1790000000.5,
      "updated_by": "admin@coop.example"
    }
  ],
  "next_cursor": null,
  "platform_default": {
    "a_levels": [
      2,
      3
    ],
    "reject_levels": [
      1,
      4
    ],
    "a_weight_kg": [
      [
        2,
        5
      ]
    ],
    "a_min_confidence": 0.8,
    "eating_window": [
      {
        "band": "ambient",
        "end_days": 7,
        "level": 1,
        "max_days": 30,
        "min_days": 0,
        "start_days": 5,
        "warning": "immature"
      },
      {
        "band": "ambient",
        "end_days": 6,
        "level": 2,
        "max_days": 1,
        "min_days": 0,
        "start_days": 4,
        "warning": null
      },
      {
        "band": "ambient",
        "end_days": 4,
        "level": 2,
        "max_days": 3,
        "min_days": 2,
        "start_days": 3,
        "warning": null
      },
      {
        "band": "ambient",
        "end_days": 2,
        "level": 2,
        "max_days": 30,
        "min_days": 4,
        "start_days": 1,
        "warning": "eat_soon"
      },
      {
        "band": "ambient",
        "end_days": 4,
        "level": 3,
        "max_days": 1,
        "min_days": 0,
        "start_days": 3,
        "warning": null
      },
      {
        "band": "ambient",
        "end_days": 3,
        "level": 3,
        "max_days": 3,
        "min_days": 2,
        "start_days": 2,
        "warning": null
      },
      {
        "band": "ambient",
        "end_days": 1,
        "level": 3,
        "max_days": 30,
        "min_days": 4,
        "start_days": 0,
        "warning": "eat_soon"
      },
      {
        "band": "ambient",
        "end_days": 1,
        "level": 4,
        "max_days": 30,
        "min_days": 0,
        "start_days": 0,
        "warning": "overripe"
      },
      {
        "band": "14-18C",
        "end_days": 10,
        "level": 1,
        "max_days": 30,
        "min_days": 0,
        "start_days": 7,
        "warning": "immature"
      },
      {
        "band": "14-18C",
        "end_days": 8,
        "level": 2,
        "max_days": 30,
        "min_days": 0,
        "start_days": 5,
        "warning": null
      },
      {
        "band": "14-18C",
        "end_days": 6,
        "level": 3,
        "max_days": 30,
        "min_days": 0,
        "start_days": 4,
        "warning": null
      },
      {
        "band": "14-18C",
        "end_days": 2,
        "level": 4,
        "max_days": 30,
        "min_days": 0,
        "start_days": 0,
        "warning": "overripe"
      },
      {
        "band": "10-13C",
        "end_days": 12,
        "level": 1,
        "max_days": 30,
        "min_days": 0,
        "start_days": 9,
        "warning": "immature"
      },
      {
        "band": "10-13C",
        "end_days": 10,
        "level": 2,
        "max_days": 30,
        "min_days": 0,
        "start_days": 7,
        "warning": null
      },
      {
        "band": "10-13C",
        "end_days": 8,
        "level": 3,
        "max_days": 30,
        "min_days": 0,
        "start_days": 5,
        "warning": null
      },
      {
        "band": "10-13C",
        "end_days": 2,
        "level": 4,
        "max_days": 30,
        "min_days": 0,
        "start_days": 0,
        "warning": "overripe"
      }
    ]
  }
}
Phản hồi 400 · application/json · bad_cursor
{
  "error": "bad cursor",
  "code": "bad_cursor"
}
Phản hồi 400 · application/json · bad_limit
{
  "error": "bad limit",
  "code": "bad_limit"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

PUT /v1/grading-rules/{variety}

Create or replace the grading rules of a variety

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: grading_rule_write · putGradingRules

Validates and stores the rules of one variety of the caller's tenant (create or replace), and records the version it wrote in the variety's history (GET /v1/grading-rules/{variety}/history) in the same transaction. Fruits are not regraded by this call: each fruit is regraded when a measurement is next bound to it or reviewed. Audited (grading_rule.update, entity id = the rule's server id, after = the eating-window row count; the variety is never recorded). Allowed for platform_admin and tenant_admin; auditor, operator and lab are refused. Second admin approval (INTEGRITY-3, #203): while the company requires a second admin (PUT /v1/company/four-eyes), a direct call answers 403 second_admin_approval_required before anything is done (no audit row, no Idempotency-Key used): ask for it with POST /v1/approval-requests, and another admin of the company approves it.

Tham số

TênVị tríKiểuMô tả
variety
bắt buộc
pathstring

Lot variety (1 to 64 characters), as on the lot.

Nội dung yêu cầu

GradingRules (bắt buộc)

Kiểu nội dung: application/json

Ví dụ yêu cầu · application/json
{
  "a_levels": [
    2,
    3
  ],
  "reject_levels": [
    1,
    4
  ],
  "a_weight_kg": [
    [
      2,
      5
    ]
  ],
  "a_min_confidence": 0.8,
  "eating_window": [
    {
      "band": "ambient",
      "end_days": 7,
      "level": 1,
      "max_days": 30,
      "min_days": 0,
      "start_days": 5,
      "warning": "immature"
    },
    {
      "band": "ambient",
      "end_days": 6,
      "level": 2,
      "max_days": 1,
      "min_days": 0,
      "start_days": 4,
      "warning": null
    },
    {
      "band": "ambient",
      "end_days": 4,
      "level": 2,
      "max_days": 3,
      "min_days": 2,
      "start_days": 3,
      "warning": null
    },
    {
      "band": "ambient",
      "end_days": 2,
      "level": 2,
      "max_days": 30,
      "min_days": 4,
      "start_days": 1,
      "warning": "eat_soon"
    },
    {
      "band": "ambient",
      "end_days": 4,
      "level": 3,
      "max_days": 1,
      "min_days": 0,
      "start_days": 3,
      "warning": null
    },
    {
      "band": "ambient",
      "end_days": 3,
      "level": 3,
      "max_days": 3,
      "min_days": 2,
      "start_days": 2,
      "warning": null
    },
    {
      "band": "ambient",
      "end_days": 1,
      "level": 3,
      "max_days": 30,
      "min_days": 4,
      "start_days": 0,
      "warning": "eat_soon"
    },
    {
      "band": "ambient",
      "end_days": 1,
      "level": 4,
      "max_days": 30,
      "min_days": 0,
      "start_days": 0,
      "warning": "overripe"
    },
    {
      "band": "14-18C",
      "end_days": 10,
      "level": 1,
      "max_days": 30,
      "min_days": 0,
      "start_days": 7,
      "warning": "immature"
    },
    {
      "band": "14-18C",
      "end_days": 8,
      "level": 2,
      "max_days": 30,
      "min_days": 0,
      "start_days": 5,
      "warning": null
    },
    {
      "band": "14-18C",
      "end_days": 6,
      "level": 3,
      "max_days": 30,
      "min_days": 0,
      "start_days": 4,
      "warning": null
    },
    {
      "band": "14-18C",
      "end_days": 2,
      "level": 4,
      "max_days": 30,
      "min_days": 0,
      "start_days": 0,
      "warning": "overripe"
    },
    {
      "band": "10-13C",
      "end_days": 12,
      "level": 1,
      "max_days": 30,
      "min_days": 0,
      "start_days": 9,
      "warning": "immature"
    },
    {
      "band": "10-13C",
      "end_days": 10,
      "level": 2,
      "max_days": 30,
      "min_days": 0,
      "start_days": 7,
      "warning": null
    },
    {
      "band": "10-13C",
      "end_days": 8,
      "level": 3,
      "max_days": 30,
      "min_days": 0,
      "start_days": 5,
      "warning": null
    },
    {
      "band": "10-13C",
      "end_days": 2,
      "level": 4,
      "max_days": 30,
      "min_days": 0,
      "start_days": 0,
      "warning": "overripe"
    }
  ]
}

Phản hồi

Mã trạng tháiKiểuMô tả
200GradingRule
application/json

The stored rules.

400Error
application/json

Invalid JSON, a body that is not an object, invalid rules, a bad variety, 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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

405Error
application/json

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

413Error
application/json

The request body is over 1 MiB.

500Error
application/json

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

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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-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-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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "id": 3,
  "tenant": "coop-dl",
  "variety": "Ri6",
  "rules": {
    "a_levels": [
      2,
      3
    ],
    "reject_levels": [
      1,
      4
    ],
    "a_weight_kg": [
      [
        2,
        5
      ]
    ],
    "a_min_confidence": 0.8,
    "eating_window": [
      {
        "band": "ambient",
        "end_days": 7,
        "level": 1,
        "max_days": 30,
        "min_days": 0,
        "start_days": 5,
        "warning": "immature"
      },
      {
        "band": "ambient",
        "end_days": 6,
        "level": 2,
        "max_days": 1,
        "min_days": 0,
        "start_days": 4,
        "warning": null
      },
      {
        "band": "ambient",
        "end_days": 4,
        "level": 2,
        "max_days": 3,
        "min_days": 2,
        "start_days": 3,
        "warning": null
      },
      {
        "band": "ambient",
        "end_days": 2,
        "level": 2,
        "max_days": 30,
        "min_days": 4,
        "start_days": 1,
        "warning": "eat_soon"
      },
      {
        "band": "ambient",
        "end_days": 4,
        "level": 3,
        "max_days": 1,
        "min_days": 0,
        "start_days": 3,
        "warning": null
      },
      {
        "band": "ambient",
        "end_days": 3,
        "level": 3,
        "max_days": 3,
        "min_days": 2,
        "start_days": 2,
        "warning": null
      },
      {
        "band": "ambient",
        "end_days": 1,
        "level": 3,
        "max_days": 30,
        "min_days": 4,
        "start_days": 0,
        "warning": "eat_soon"
      },
      {
        "band": "ambient",
        "end_days": 1,
        "level": 4,
        "max_days": 30,
        "min_days": 0,
        "start_days": 0,
        "warning": "overripe"
      },
      {
        "band": "14-18C",
        "end_days": 10,
        "level": 1,
        "max_days": 30,
        "min_days": 0,
        "start_days": 7,
        "warning": "immature"
      },
      {
        "band": "14-18C",
        "end_days": 8,
        "level": 2,
        "max_days": 30,
        "min_days": 0,
        "start_days": 5,
        "warning": null
      },
      {
        "band": "14-18C",
        "end_days": 6,
        "level": 3,
        "max_days": 30,
        "min_days": 0,
        "start_days": 4,
        "warning": null
      },
      {
        "band": "14-18C",
        "end_days": 2,
        "level": 4,
        "max_days": 30,
        "min_days": 0,
        "start_days": 0,
        "warning": "overripe"
      },
      {
        "band": "10-13C",
        "end_days": 12,
        "level": 1,
        "max_days": 30,
        "min_days": 0,
        "start_days": 9,
        "warning": "immature"
      },
      {
        "band": "10-13C",
        "end_days": 10,
        "level": 2,
        "max_days": 30,
        "min_days": 0,
        "start_days": 7,
        "warning": null
      },
      {
        "band": "10-13C",
        "end_days": 8,
        "level": 3,
        "max_days": 30,
        "min_days": 0,
        "start_days": 5,
        "warning": null
      },
      {
        "band": "10-13C",
        "end_days": 2,
        "level": 4,
        "max_days": 30,
        "min_days": 0,
        "start_days": 0,
        "warning": "overripe"
      }
    ]
  },
  "updated_at": 1790000000.5,
  "updated_by": "admin@coop.example"
}
Phản hồi 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
Phản hồi 400 · application/json · not_an_object
{
  "error": "expected a JSON object",
  "code": "expected_a_json_object"
}
Phản hồi 400 · application/json · invalid_rules
{
  "error": "invalid rules: a_weight_kg bands must not overlap",
  "code": "invalid_rules"
}
Phản hồi 400 · application/json · invalid_variety
{
  "error": "invalid variety: a string of 1 to 64 characters",
  "code": "invalid_variety"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots

Lots of the caller's tenant

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · listLots

Newest first (by seq) with keyset pagination, optionally only one status or facility. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities).

Tham số

TênVị tríKiểuMô tả
cursor
không bắt buộc
querystring

next_cursor of the previous page.

limit
không bắt buộc
queryinteger

Page size, 1 to 200.

status
không bắt buộc
query"draft" | "open" | "paused" | "closed" | "packed" | "shipped" | "recalled" | "withdrawn"

Only lots in this status.

facility
không bắt buộc
querystring

Only lots of this facility.

Phản hồi

Mã trạng tháiKiểuMô tả
200LotPage
application/json

One page of lots.

400Error
application/json

A cursor this API did not issue, a limit outside 1 to 200, an unknown status, a facility value over 256 characters, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "items": [
    {
      "tenant": "coop-dl",
      "code": "LO-260928-014",
      "seq": 14,
      "public_id": "5f0c8e2a9b7d4c1e8a3f6b2d9c0e7a14",
      "facility": "VN-TGPH-021",
      "product": "durian",
      "variety": "Ri6",
      "growing_area": "VN-TGOR-0387",
      "harvest_date": "2026-09-27",
      "harvest_event_id": null,
      "destination": "Huu Nghi border gate, Lang Son",
      "gtin": "00012345678905",
      "status": "open",
      "created_at": 1790000000.5,
      "updated_at": 1790000000.5,
      "closed_at": null
    }
  ],
  "next_cursor": null
}
Phản hồi 400 · application/json · bad_cursor
{
  "error": "bad cursor",
  "code": "bad_cursor"
}
Phản hồi 400 · application/json · bad_limit
{
  "error": "bad limit",
  "code": "bad_limit"
}
Phản hồi 400 · application/json · bad_status
{
  "error": "bad status",
  "code": "bad_status"
}
Phản hồi 400 · application/json · bad_facility
{
  "error": "bad facility",
  "code": "bad_facility"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/lots

Create a lot

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · createLot

Creates a draft lot owned by the tenant the caller acts for, with the next lot number (seq) of the tenant and a random public id. The code is unique within the tenant (the same code in another tenant is another lot) and immutable. Audited (lot.create). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only within its facilities); auditor and lab are refused.

Tham số

TênVị tríKiểuMô tả
Idempotency-Key
không bắt buộc
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.

Nội dung yêu cầu

LotCreate (bắt buộc)

Kiểu nội dung: application/json

Ví dụ yêu cầu · application/json
{
  "code": "LO-260928-014",
  "facility": "VN-TGPH-021",
  "variety": "Ri6",
  "growing_area": "VN-TGOR-0387",
  "harvest_date": "2026-09-27",
  "destination": "Huu Nghi border gate, Lang Son"
}

Phản hồi

Mã trạng tháiKiểuMô tả
201Lot
application/json

The new lot.

400Error
application/json

Invalid JSON, an unknown field, a bad code, a facility that is missing, of another tenant or outside an operator's facilities, an unknown growing area or harvest event, a bad GTIN or date, a value out of bounds, a product that names no crop of the crop registry and no configured crop, 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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

405Error
application/json

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

409Error
application/json

The tenant already has a lot with this code. 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). SELF-2-8 (#197): or the facility is a company's proposal CropPath has not approved yet.

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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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-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.

Ví dụ phản hồi

Phản hồi 201 · application/json
{
  "tenant": "coop-dl",
  "code": "LO-260928-014",
  "seq": 14,
  "public_id": "5f0c8e2a9b7d4c1e8a3f6b2d9c0e7a14",
  "facility": "VN-TGPH-021",
  "product": "durian",
  "variety": "Ri6",
  "growing_area": "VN-TGOR-0387",
  "harvest_date": "2026-09-27",
  "harvest_event_id": null,
  "destination": "Huu Nghi border gate, Lang Son",
  "gtin": "00012345678905",
  "status": "draft",
  "created_at": 1790000000.5,
  "updated_at": 1790000000.5,
  "closed_at": null
}
Phản hồi 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
Phản hồi 400 · application/json · unknown_field
{
  "error": "unknown field",
  "code": "unknown_field"
}
Phản hồi 400 · application/json · invalid_code
{
  "error": "invalid code: 3 to 40 upper-case letters, digits or '-', starting with a letter or digit",
  "code": "invalid_code"
}
Phản hồi 400 · application/json · unknown_facility
{
  "error": "unknown facility",
  "code": "unknown_facility"
}
Phản hồi 400 · application/json · unknown_growing_area
{
  "error": "unknown growing area",
  "code": "unknown_growing_area"
}
Phản hồi 400 · application/json · unknown_harvest_event
{
  "error": "unknown harvest event",
  "code": "unknown_harvest_event"
}
Phản hồi 400 · application/json · invalid_gtin
{
  "error": "invalid gtin: 14 digits with a valid GS1 check digit",
  "code": "invalid_gtin"
}
Phản hồi 400 · application/json · invalid_harvest_date
{
  "error": "invalid harvest_date: later than today",
  "code": "invalid_harvest_date"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · lot_code_already_exists
{
  "error": "lot code already exists",
  "code": "lot_code_already_exists"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · facility_not_approved
{
  "error": "facility not approved",
  "code": "facility_not_approved"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/suggested-code

A suggested code for the next lot

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · suggestLotCode

#315: the code the console's create-lot form pre-fills, LO-YYMMDD-NNN: YYMMDD is today in Asia/Ho_Chi_Minh and NNN the number after the highest one the selected company (X-Tenant) used that day in a code of this form (three digits, zero-padded; more digits past 999), or the lowest free number when that would make the code longer than 40 characters. It is counted over the whole company, whatever the caller's packing houses, because lot codes are unique within the company. The code stays the company's choice: any code createLot accepts may be sent instead. Nothing is reserved, so two callers may get the same suggestion: createLot refuses the second (409 lot_code_already_exists), and a new suggestion is the next number. Read-only and not audited (a read). Allowed for the callers who may create a lot: platform_admin, tenant_admin and an operator signed in with a session; auditors and lab users are refused (403). Not part of the partner SDK clients (x-not-in-sdk): an operation of the console's create-lot form.

Phản hồi

Mã trạng tháiKiểuMô tả
200LotCodeSuggestion
application/json

The suggested code.

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

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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "code": "LO-261019-001"
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/{lot}

One lot

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · getLot

The lot of the caller's tenant with this code. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities).

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Phản hồi

Mã trạng tháiKiểuMô tả
200Lot
application/json

The lot.

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 lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "tenant": "coop-dl",
  "code": "LO-260928-014",
  "seq": 14,
  "public_id": "5f0c8e2a9b7d4c1e8a3f6b2d9c0e7a14",
  "facility": "VN-TGPH-021",
  "product": "durian",
  "variety": "Ri6",
  "growing_area": "VN-TGOR-0387",
  "harvest_date": "2026-09-27",
  "harvest_event_id": null,
  "destination": "Huu Nghi border gate, Lang Son",
  "gtin": "00012345678905",
  "status": "open",
  "created_at": 1790000000.5,
  "updated_at": 1790000000.5,
  "closed_at": null
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

PATCH /v1/lots/{lot}

Edit a lot

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · updateLot

Changes descriptive fields while the lot is draft or open. The GTIN freezes once the lot has fruit records. Audited (lot.update). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only within its facilities); auditor and lab are refused.

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Nội dung yêu cầu

LotUpdate (bắt buộc)

Kiểu nội dung: application/json

Ví dụ yêu cầu · application/json
{
  "variety": "Ri6",
  "destination": null
}

Phản hồi

Mã trạng tháiKiểuMô tả
200Lot
application/json

The lot after the change.

400Error
application/json

Invalid JSON, an immutable or unknown field, an empty body, an invalid value, a product that names no crop of the crop registry and no configured crop, 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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The lot is no longer editable, or the GTIN is frozen.

413Error
application/json

The request body is over 1 MiB.

500Error
application/json

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

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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-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-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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "tenant": "coop-dl",
  "code": "LO-260928-014",
  "seq": 14,
  "public_id": "5f0c8e2a9b7d4c1e8a3f6b2d9c0e7a14",
  "facility": "VN-TGPH-021",
  "product": "durian",
  "variety": "Ri6",
  "growing_area": "VN-TGOR-0387",
  "harvest_date": "2026-09-27",
  "harvest_event_id": null,
  "destination": "Huu Nghi border gate, Lang Son",
  "gtin": "00012345678905",
  "status": "open",
  "created_at": 1790000000.5,
  "updated_at": 1790000000.5,
  "closed_at": null
}
Phản hồi 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
Phản hồi 400 · application/json · immutable
{
  "error": "code is immutable",
  "code": "code_is_immutable"
}
Phản hồi 400 · application/json · unknown_field
{
  "error": "unknown field",
  "code": "unknown_field"
}
Phản hồi 400 · application/json · empty
{
  "error": "nothing to update",
  "code": "nothing_to_update"
}
Phản hồi 400 · application/json · invalid_gtin
{
  "error": "invalid gtin: 14 digits with a valid GS1 check digit",
  "code": "invalid_gtin"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · closed
{
  "error": "lot is closed",
  "code": "lot_is_closed"
}
Phản hồi 409 · application/json · gtin_frozen
{
  "error": "gtin is frozen: the lot already has fruit records",
  "code": "gtin_is_frozen"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/{lot}/fruits

Fruits of a lot

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · listLotFruits

The lot's fruits in allocation order (n ascending, across all of its sessions) with keyset pagination, optionally only one status and/or the codes starting with q. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities). Not audited (a read).

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

q
không bắt buộc
querystring

Fruit code prefix, case-insensitive: 1 to 32 letters, digits or '-'.

status
không bắt buộc
query"awaiting_device" | "recorded" | "overridden" | "rejected" | "remeasured"

Only fruits with this status.

cursor
không bắt buộc
querystring

next_cursor of the previous page.

limit
không bắt buộc
queryinteger

Page size, 1 to 200.

Phản hồi

Mã trạng tháiKiểuMô tả
200FruitPage
application/json

One page of the lot's fruits.

400Error
application/json

A query that is not a code prefix, an unknown status, a cursor this API did not issue, a limit outside 1 to 200, 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 lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "items": [
    {
      "tenant": "coop-dl",
      "code": "Q-014-0129",
      "n": 129,
      "public_id": "5f0c9a1e7b2d4c3a8e6f1b0d9c7a2e4f",
      "lot": "LO-260928-014",
      "session": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
      "line": "A2",
      "operator": "user-7",
      "status": "recorded",
      "labels_printed_at": 1790000000.5,
      "created_at": 1790000000.5,
      "updated_at": 1790560561.2,
      "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7",
      "level": 3,
      "level_pred": 3,
      "maturity_class": "mature",
      "confidence": 0.91,
      "model": "sf100-m3",
      "measured_at": 1790560560,
      "weight_kg": 2.84,
      "level_sensory": null,
      "override": false,
      "pending_review": false,
      "grade": "A",
      "eating_window": {
        "start_days": 3,
        "end_days": 4,
        "from_date": "2026-10-01",
        "to_date": "2026-10-02",
        "band": "ambient",
        "warning": null
      },
      "record_tier": "device_recorded",
      "knock_envelope_id": "0b9c2f4e-7d1a-4c3e-9f8b-2a6d5e1c7b30",
      "scale_envelope_id": "6e3a1d9c-2b7f-4e8a-b5c4-9d0f1e2a3b47",
      "override_envelope_id": null
    }
  ],
  "next_cursor": "eyJuIjoxMjl9"
}
Phản hồi 400 · application/json · bad_query
{
  "error": "bad query",
  "code": "bad_query"
}
Phản hồi 400 · application/json · bad_status
{
  "error": "bad status",
  "code": "bad_status"
}
Phản hồi 400 · application/json · bad_cursor
{
  "error": "bad cursor",
  "code": "bad_cursor"
}
Phản hồi 400 · application/json · bad_limit
{
  "error": "bad limit",
  "code": "bad_limit"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/{lot}/sessions

Measurement sessions of a lot

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · listLotSessions

Every measurement session of the lot, newest first (by opened_at), each with the devices chosen when it opened. Not paginated: a line holds at most one open or paused session, so a lot has few. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities). Not audited (a read).

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Phản hồi

Mã trạng tháiKiểuMô tả
200MeasurementSessionList
application/json

The lot's measurement sessions, newest first.

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 lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "items": [
    {
      "id": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
      "tenant": "coop-dl",
      "lot": "LO-260928-014",
      "facility": "VN-TGPH-021",
      "line": "A2",
      "status": "open",
      "opened_by": "operator@coop.example",
      "opened_at": 1790000000.5,
      "paused_at": null,
      "closed_at": null,
      "updated_at": 1790000000.5,
      "devices": [
        "knk-1",
        "scale-1"
      ]
    },
    {
      "id": "8c4a2d1e-5b6f-4e3a-9d7c-1f0b2e4a6c58",
      "tenant": "coop-dl",
      "lot": "LO-260928-014",
      "facility": "VN-TGPH-021",
      "line": "A1",
      "status": "closed",
      "opened_by": "operator@coop.example",
      "opened_at": 1789990000.5,
      "paused_at": null,
      "closed_at": 1789995000.5,
      "updated_at": 1789995000.5,
      "devices": [
        "knk-1"
      ]
    }
  ]
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/lots/{lot}/sessions

Open a measurement session

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · openMeasurementSession

Opens a session of the lot on one line of the lot's facility (a draft lot becomes open), records the chosen devices, then sends set_session {lot, line[, operator]} to each chosen device whose profile declares it (operator is user-<id> for a signed-in user). A device without set_session is skipped and a transport failure is reported per device; neither undoes the session. A lot that was sampled (POST /v1/lots/{lot}/samples) takes no new session: 409 lot sampled, its export population is final. Audited (session.open). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only within its facilities); auditor and lab are refused.

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Idempotency-Key
không bắt buộc
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.

Nội dung yêu cầu

MeasurementSessionOpen (bắt buộc)

Kiểu nội dung: application/json

Ví dụ yêu cầu · application/json
{
  "line": "A2",
  "devices": [
    "knk-1",
    "scale-1"
  ]
}

Phản hồi

Mã trạng tháiKiểuMô tả
201MeasurementSessionOpened
application/json

The new session and the set_session outcome per device.

400Error
application/json

Invalid JSON, an unknown field, a bad line, a bad device list, a device that is not an active device of the lot's facility, no device list while more than 16 devices of the facility declare set_session, 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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The lot is closed or was sampled, the line already has an open or paused session, or a chosen device is in one. 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 201 · application/json
{
  "id": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "tenant": "coop-dl",
  "lot": "LO-260928-014",
  "facility": "VN-TGPH-021",
  "line": "A2",
  "status": "open",
  "opened_by": "operator@coop.example",
  "opened_at": 1790000000.5,
  "paused_at": null,
  "closed_at": null,
  "updated_at": 1790000000.5,
  "devices": [
    "knk-1",
    "scale-1"
  ],
  "commands": [
    {
      "device_id": "knk-1",
      "command_id": "9d2e7f40-1c3b-4a5e-8f6d-0b7c2a9e4d18",
      "status": "sent",
      "reason": null
    },
    {
      "device_id": "scale-1",
      "command_id": null,
      "status": "skipped",
      "reason": "not_declared"
    }
  ]
}
Phản hồi 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
Phản hồi 400 · application/json · unknown_field
{
  "error": "unknown field",
  "code": "unknown_field"
}
Phản hồi 400 · application/json · invalid_line
{
  "error": "invalid line: 1 to 16 upper-case letters, digits or '-', starting with a letter or digit",
  "code": "invalid_line"
}
Phản hồi 400 · application/json · invalid_devices
{
  "error": "invalid devices: at most 16 distinct device ids",
  "code": "invalid_devices"
}
Phản hồi 400 · application/json · unknown_device
{
  "error": "unknown device",
  "code": "unknown_device"
}
Phản hồi 400 · application/json · too_many_devices
{
  "error": "too many devices: more than 16 devices of the facility declare set_session; send an explicit devices list",
  "code": "too_many_devices"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · lot_closed
{
  "error": "lot is closed",
  "code": "lot_is_closed"
}
Phản hồi 409 · application/json · line_busy
{
  "error": "line busy",
  "code": "line_busy"
}
Phản hồi 409 · application/json · device_busy
{
  "error": "device busy: knk-1",
  "code": "device_busy"
}
Phản hồi 409 · application/json · lot_sampled
{
  "error": "lot sampled: its export population is final",
  "code": "lot_sampled"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/{lot}/summary

Lot summary

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · getLotSummary

What the lot holds so far (man1 'lot so far'), aggregated over its fruit records: count fruits with a device record (status recorded or overridden, or rejected with a bound device envelope; awaiting_device and rejected_unmeasured, rejected before any measurement, apart), kg from the scale (rounded to 3 decimals) over the weighed ones, counts per effective ripeness level (the sensory level when overridden), per grade (a rejected fruit is a reject whatever its grade), sensory overrides, the mean device confidence, fruits pending review, what is exportable (A or B, not rejected) and the volume headroom of the lot's growing area for the season of its harvest date (null without a growing area). Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities). Not audited (a read).

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Phản hồi

Mã trạng tháiKiểuMô tả
200LotSummary
application/json

The lot's summary.

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 lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "lot": "LO-260928-014",
  "status": "open",
  "count": 128,
  "awaiting_device": 0,
  "rejected_unmeasured": 0,
  "kg": 364.2,
  "weighed": 123,
  "levels": {
    "1": 7,
    "2": 38,
    "3": 78,
    "4": 5,
    "unknown": 0
  },
  "grades": {
    "A": 96,
    "B": 27,
    "reject": 5,
    "ungraded": 0
  },
  "overrides": 3,
  "avg_confidence": 0.8884,
  "pending_review": 0,
  "export": {
    "count": 123,
    "kg": 364.2
  },
  "volume": {
    "growing_area": "VN-TGOR-0387",
    "season": "2026",
    "declared_kg": 760,
    "cap_kg": 2000,
    "headroom_kg": 1240
  }
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/{lot}/applications

Application records in the lot history

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · listLotApplications

#241: the company's application records (apply events: water, fertiliser, pesticide, lime or light) on the lot's growing area during the season before its harvest, oldest first: dated from the longest pre-harvest interval a record may state after the longest application (365 days and one day) before the lot's harvest day (00:00 Asia/Ho_Chi_Minh) up to the end of that day, so every record whose interval could still be open at a harvest that day. The harvest day is the lot's harvest date, else the date of its harvest record, else the date the lot was created. Accepted and held (quarantined) records are listed; a record rejected after review is not. At most the 200 nearest the harvest, still oldest first (more says older ones were left out). A record entered by hand in the harvest app (harvest_app) is Self-declared. A lot without a growing area lists none. #322: sprays lists the spray records of the growing area's spray log (the console's spray records, as GET /v1/growing-areas/{code}/sprays and the public fruit record read them) sprayed from the first day of the same period to the harvest day, with their withholding status at the harvest day, so the lot's inputs and its growing area's spray log agree; they are listed only and hold no harvest. Staff only: the public record does not show them. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities). Not audited (a read). Not part of the partner SDK clients (x-not-in-sdk): SDK 0.2.0 was released before it.

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Phản hồi

Mã trạng tháiKiểuMô tả
200LotApplications
application/json

The lot's application records.

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 lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "lot": "LO-260928-014",
  "growing_area": "VN-TGOR-0387",
  "from": "2025-09-25T17:00:00Z",
  "until": "2026-09-27T17:00:00Z",
  "items": [
    {
      "id": "7c0e9a52-4f1b-4d8e-9b0a-2f6c3d1e5a77",
      "applied_at": "2026-09-10T00:30:00Z",
      "input": "pesticide",
      "product": {
        "id": "VN-REG-0001",
        "batch": "B-7",
        "name": null
      },
      "product_mass_kg": null,
      "product_volume_l": 1.5,
      "duration_s": null,
      "phi_days": 14,
      "interval_ends_at": "2026-09-24T00:30:00Z",
      "status": "accepted",
      "reasons": [],
      "device_id": "harvest-761ccd0930ffbe627fbe6d72",
      "operator": "op-7",
      "harvest_app": true
    }
  ],
  "more": false,
  "sprays": [
    {
      "id": 3,
      "sprayed_on": "2026-09-01",
      "product": "Ridomil Gold",
      "active_ingredient": "metalaxyl-M",
      "withholding_days": 14,
      "safe_from": "2026-09-15",
      "withholding_status": "ok"
    }
  ]
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/sessions/{id}

One measurement session

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · getMeasurementSession

A measurement session of the caller's tenant (not a login session). Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities).

Tham số

TênVị tríKiểuMô tả
id
bắt buộc
pathstring

Measurement session id.

Phản hồi

Mã trạng tháiKiểuMô tả
200MeasurementSession
application/json

The session.

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 measurement session for this tenant: a session of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "id": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "tenant": "coop-dl",
  "lot": "LO-260928-014",
  "facility": "VN-TGPH-021",
  "line": "A2",
  "status": "open",
  "opened_by": "operator@coop.example",
  "opened_at": 1790000000.5,
  "paused_at": null,
  "closed_at": null,
  "updated_at": 1790000000.5,
  "devices": [
    "knk-1",
    "scale-1"
  ]
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: 3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/sessions/{id}/close

Close a measurement session

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · closeMeasurementSession

open or paused -> closed. Sets closed_at and frees the line. Any other state is 409 invalid transition. Audited (session.close). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only within its facilities); auditor and lab are refused.

Tham số

TênVị tríKiểuMô tả
id
bắt buộc
pathstring

Measurement session id.

Idempotency-Key
không bắt buộc
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.

Phản hồi

Mã trạng tháiKiểuMô tả
200MeasurementSession
application/json

The session after the change.

400Error
application/json

The X-Request-Id header is present and malformed, or the Idempotency-Key header is malformed or repeated.

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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such measurement session for this tenant: a session of another tenant, or of a facility outside an operator's facilities, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The session is not in a state this action leaves. 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).

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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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-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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "id": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "tenant": "coop-dl",
  "lot": "LO-260928-014",
  "facility": "VN-TGPH-021",
  "line": "A2",
  "status": "closed",
  "opened_by": "operator@coop.example",
  "opened_at": 1790000000.5,
  "paused_at": null,
  "closed_at": 1790000000.5,
  "updated_at": 1790000000.5,
  "devices": [
    "knk-1",
    "scale-1"
  ]
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: 3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · invalid_transition
{
  "error": "invalid transition: closed to closed",
  "code": "invalid_transition"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/sessions/{id}/feed

What changed on a measurement session after a cursor

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · getSessionFeed

The session's fruit upserts with an rx_seq above after, ascending (only this session's fruits; a fruit changed several times since after appears once, with its latest rx_seq), and a status snapshot: the session's status, the status read model of every device stored on the session, the scale live weight (the newest numeric mass.net reading among each session device's latest 32 stored envelopes of any kind) and the pending counts of the session's fruits. Poll it with after = next_after (the fallback when the stream answers 503). Not audited. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the sessions of its facilities); a lab is refused.

Tham số

TênVị tríKiểuMô tả
id
bắt buộc
pathstring

Measurement session id.

after
không bắt buộc
queryinteger

Return the fruit upserts with an rx_seq above this one (next_after of the previous call); a decimal integer from 0 to 2^63-1.

limit
không bắt buộc
queryinteger

At most this many fruit upserts, 1 to 200.

Phản hồi

Mã trạng tháiKiểuMô tả
200SessionFeed
application/json

The fruit upserts after the cursor and the status snapshot.

400Error
application/json

An after that is not an integer from 0 to 2^63-1, a limit outside 1 to 200, 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 measurement session for this tenant: a session of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "items": [
    {
      "rx_seq": 413,
      "fruit": {
        "tenant": "coop-dl",
        "code": "Q-014-0129",
        "n": 129,
        "public_id": "5f0c9a1e7b2d4c3a8e6f1b0d9c7a2e4f",
        "lot": "LO-260928-014",
        "session": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
        "line": "A2",
        "operator": "user-7",
        "status": "awaiting_device",
        "labels_printed_at": 1790000000.5,
        "created_at": 1790000000.5,
        "updated_at": 1790000000.5,
        "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7",
        "level": null,
        "level_pred": null,
        "maturity_class": null,
        "confidence": null,
        "model": null,
        "measured_at": null,
        "weight_kg": null,
        "level_sensory": null,
        "override": false,
        "pending_review": false,
        "grade": null,
        "eating_window": null,
        "record_tier": null,
        "knock_envelope_id": null,
        "scale_envelope_id": null,
        "override_envelope_id": null
      }
    }
  ],
  "next_after": 413,
  "session_status": "open",
  "devices": [
    {
      "device_id": "knk-1",
      "tenant": "coop-dl",
      "site": "ph1",
      "facility": "VN-TGPH-021",
      "profile": "vn.agritrace.durian-knocker",
      "status": "active",
      "display_name": "Knocker line 1",
      "vendor_model": "SF-100",
      "serial": "SF100-000123",
      "created_at": 1790000000.5,
      "commands": [
        "calibrate",
        "set_model",
        "set_session"
      ],
      "last_seen": 1790003600.25,
      "max_seq": 412,
      "last_model": "m1",
      "firmware": "1.4.2",
      "battery_pct": 87,
      "battery_v": 3.92,
      "last_calibrated_at": 1789990000,
      "ready": true,
      "approval": "approved",
      "approval_reason": null,
      "approval_at": 1790000100
    }
  ],
  "scale": {
    "device_id": "scl-st",
    "weight_kg": 2.84,
    "at": 1790003600.25
  },
  "pending": {
    "awaiting_device": 1,
    "pending_review": 0
  }
}
Phản hồi 400 · application/json · bad_cursor
{
  "error": "bad cursor",
  "code": "bad_cursor"
}
Phản hồi 400 · application/json · bad_limit
{
  "error": "bad limit",
  "code": "bad_limit"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: 3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/sessions/{id}/fruits

Fruits of a measurement session

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · listSessionFruits

The session's fruits in allocation order (n ascending) with keyset pagination. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the sessions of its facilities).

Tham số

TênVị tríKiểuMô tả
id
bắt buộc
pathstring

Measurement session id.

cursor
không bắt buộc
querystring

next_cursor of the previous page.

limit
không bắt buộc
queryinteger

Page size, 1 to 200.

Phản hồi

Mã trạng tháiKiểuMô tả
200FruitPage
application/json

One page of fruits.

400Error
application/json

A cursor this API did not issue, a limit outside 1 to 200, 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 measurement session for this tenant: a session of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "items": [
    {
      "tenant": "coop-dl",
      "code": "Q-014-0129",
      "n": 129,
      "public_id": "5f0c9a1e7b2d4c3a8e6f1b0d9c7a2e4f",
      "lot": "LO-260928-014",
      "session": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
      "line": "A2",
      "operator": "user-7",
      "status": "awaiting_device",
      "labels_printed_at": 1790000000.5,
      "created_at": 1790000000.5,
      "updated_at": 1790000000.5,
      "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7",
      "level": null,
      "level_pred": null,
      "maturity_class": null,
      "confidence": null,
      "model": null,
      "measured_at": null,
      "weight_kg": null,
      "level_sensory": null,
      "override": false,
      "pending_review": false,
      "grade": null,
      "eating_window": null,
      "record_tier": null,
      "knock_envelope_id": null,
      "scale_envelope_id": null,
      "override_envelope_id": null
    }
  ],
  "next_cursor": null
}
Phản hồi 400 · application/json · bad_cursor
{
  "error": "bad cursor",
  "code": "bad_cursor"
}
Phản hồi 400 · application/json · bad_limit
{
  "error": "bad limit",
  "code": "bad_limit"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: 3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/sessions/{id}/fruits

Allocate the next fruit of a measurement session

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · allocateFruit

Allocates the next fruit of the session's lot: n is gap-free per lot across all of its sessions and the code is Q-<lot seq, 3+ digits>-<n, 4+ digits>. The label is printed now (labels_printed_at); the operator is the caller (user-<id> for a signed-in user, none for API tokens), never a body field. After the fruit is stored, set_session {lot, fruit, line[, operator]} goes to every device of the session whose profile declares it; a device without it is skipped and a transport failure is reported per device, neither undoes the fruit. Only an open session of a draft or open lot allocates. Audited (fruit.allocate). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only within its facilities); auditor and lab are refused.

Tham số

TênVị tríKiểuMô tả
id
bắt buộc
pathstring

Measurement session id.

Idempotency-Key
không bắt buộc
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.

Nội dung yêu cầu

FruitAllocate (không bắt buộc)

Kiểu nội dung: application/json

Ví dụ yêu cầu · application/json
{}

Phản hồi

Mã trạng tháiKiểuMô tả
201FruitAllocated
application/json

The new fruit, its label payload and the set_session outcome per device.

400Error
application/json

Invalid JSON, a body that is not an object, any body field, 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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such measurement session for this tenant: a session of another tenant, or of a facility outside an operator's facilities, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The session's lot is past open, or the session is paused or closed. 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 201 · application/json
{
  "tenant": "coop-dl",
  "code": "Q-014-0129",
  "n": 129,
  "public_id": "5f0c9a1e7b2d4c3a8e6f1b0d9c7a2e4f",
  "lot": "LO-260928-014",
  "session": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "line": "A2",
  "operator": "user-7",
  "status": "awaiting_device",
  "labels_printed_at": 1790000000.5,
  "created_at": 1790000000.5,
  "updated_at": 1790000000.5,
  "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7",
  "label": {
    "code": "Q-014-0129",
    "lot": "LO-260928-014",
    "n": 129,
    "line": "A2",
    "operator": "user-7",
    "printed_at": 1790000000.5,
    "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7"
  },
  "commands": [
    {
      "device_id": "knk-1",
      "command_id": "9d2e7f40-1c3b-4a5e-8f6d-0b7c2a9e4d18",
      "status": "sent",
      "reason": null
    },
    {
      "device_id": "scale-1",
      "command_id": "1a6b3c8d-2e4f-4a7b-9c0d-5e8f1a2b3c4d",
      "status": "sent",
      "reason": null
    }
  ],
  "level": null,
  "level_pred": null,
  "maturity_class": null,
  "confidence": null,
  "model": null,
  "measured_at": null,
  "weight_kg": null,
  "level_sensory": null,
  "override": false,
  "pending_review": false,
  "grade": null,
  "eating_window": null,
  "record_tier": null,
  "knock_envelope_id": null,
  "scale_envelope_id": null,
  "override_envelope_id": null
}
Phản hồi 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
Phản hồi 400 · application/json · not_an_object
{
  "error": "expected a JSON object",
  "code": "expected_a_json_object"
}
Phản hồi 400 · application/json · unknown_field
{
  "error": "unknown field",
  "code": "unknown_field"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: 3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · lot_closed
{
  "error": "lot is closed",
  "code": "lot_is_closed"
}
Phản hồi 409 · application/json · session_paused
{
  "error": "session is paused",
  "code": "session_is_paused"
}
Phản hồi 409 · application/json · session_closed
{
  "error": "session is closed",
  "code": "session_is_closed"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/sessions/{id}/pause

Pause a measurement session

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · pauseMeasurementSession

open -> paused. Sets paused_at; the session keeps its line. Any other state is 409 invalid transition. Audited (session.pause). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only within its facilities); auditor and lab are refused.

Tham số

TênVị tríKiểuMô tả
id
bắt buộc
pathstring

Measurement session id.

Idempotency-Key
không bắt buộc
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.

Phản hồi

Mã trạng tháiKiểuMô tả
200MeasurementSession
application/json

The session after the change.

400Error
application/json

The X-Request-Id header is present and malformed, or the Idempotency-Key header is malformed or repeated.

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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such measurement session for this tenant: a session of another tenant, or of a facility outside an operator's facilities, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The session is not in a state this action leaves. 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).

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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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-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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "id": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "tenant": "coop-dl",
  "lot": "LO-260928-014",
  "facility": "VN-TGPH-021",
  "line": "A2",
  "status": "paused",
  "opened_by": "operator@coop.example",
  "opened_at": 1790000000.5,
  "paused_at": 1790000000.5,
  "closed_at": null,
  "updated_at": 1790000000.5,
  "devices": [
    "knk-1",
    "scale-1"
  ]
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: 3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · invalid_transition
{
  "error": "invalid transition: paused to paused",
  "code": "invalid_transition"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/sessions/{id}/resume

Resume a measurement session

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · resumeMeasurementSession

paused -> open. Any other state is 409 invalid transition. Audited (session.resume). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only within its facilities); auditor and lab are refused.

Tham số

TênVị tríKiểuMô tả
id
bắt buộc
pathstring

Measurement session id.

Idempotency-Key
không bắt buộc
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.

Phản hồi

Mã trạng tháiKiểuMô tả
200MeasurementSession
application/json

The session after the change.

400Error
application/json

The X-Request-Id header is present and malformed, or the Idempotency-Key header is malformed or repeated.

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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such measurement session for this tenant: a session of another tenant, or of a facility outside an operator's facilities, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The session is not in a state this action leaves. 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).

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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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-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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "id": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "tenant": "coop-dl",
  "lot": "LO-260928-014",
  "facility": "VN-TGPH-021",
  "line": "A2",
  "status": "open",
  "opened_by": "operator@coop.example",
  "opened_at": 1790000000.5,
  "paused_at": null,
  "closed_at": null,
  "updated_at": 1790000000.5,
  "devices": [
    "knk-1",
    "scale-1"
  ]
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: 3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · invalid_transition
{
  "error": "invalid transition: open to open",
  "code": "invalid_transition"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/sessions/{id}/stream

Live server-sent events of a measurement session

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · streamSession

A text/event-stream (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 fruit upsert after the resume point as id: <rx_seq> / event: fruit / data: {rx_seq, fruit} in rx_seq order; event: status (no id, so it never moves the client's cursor) with {session_status, devices, scale, pending} (as in the feed) once at the start and whenever it changes; a : hb comment after 15 s without output; and, once the session is closed and its backlog sent, event: end with {"reason": "session_closed"}. The server polls once a second 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 0. At most 64 streams per backend process, at most half of them (32) for one tenant and at most 4 for one principal (a signed-in user or an API token): above any of these the answer is 503 with Retry-After: 2 and the client polls the feed every 2 s. Authentication, the role check, the parameters and the session lookup 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 grant that no longer covers the session ends the stream at once, without an end event (the reconnect is then refused). EventSource cannot send X-Tenant: a session principal streams its default tenant. Not audited. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the sessions of its facilities); a lab is refused.

Tham số

TênVị tríKiểuMô tả
id
bắt buộc
pathstring

Measurement session id.

Last-Event-ID
không bắt buộc
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
không bắt buộc
queryinteger

Return the fruit upserts with an rx_seq above this one (next_after of the previous call); a decimal integer from 0 to 2^63-1.

Phản hồi

Mã trạng tháiKiểuMô tả
200string
text/event-stream

The event stream.

400Error
application/json

A malformed Last-Event-ID or after, 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 measurement session for this tenant: a session of another tenant, or of a facility outside an operator's facilities, 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.

503Error
application/json

Too many concurrent streams on this backend process, for the caller's tenant or for the caller; poll the feed instead and retry after Retry-After seconds.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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-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.

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.

Ví dụ phản hồi

Phản hồi 200 · text/event-stream
retry: 2000

id: 413
event: fruit
data: {"rx_seq":413,"fruit":{"code":"Q-014-0129","status":"recorded"}}

event: status
data: {"session_status":"open","devices":[],"scale":null,"pending":{"awaiting_device":0,"pending_review":0}}

: hb

event: end
data: {"reason":"session_closed"}

Phản hồi 400 · application/json · bad_last_event_id
{
  "error": "bad last event id",
  "code": "bad_last_event_id"
}
Phản hồi 400 · application/json · bad_cursor
{
  "error": "bad cursor",
  "code": "bad_cursor"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: 3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}
Phản hồi 503 · application/json
{
  "error": "too many streams",
  "code": "too_many_streams"
}

GET /v1/lots/{lot}/samples

A lot's sampling

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · getLotSampling

The lot's sampling, or {"sampling": null} when it was not sampled. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities). Not audited (a read).

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Phản hồi

Mã trạng tháiKiểuMô tả
200LotSamplingRead
application/json

The lot's sampling.

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 lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "sampling": {
    "lot": "LO-260928-014",
    "lab": {
      "code": "LAB-VN-118",
      "name": "Phòng thử nghiệm mẫu"
    },
    "rule": {
      "id": "cn-durian-protocol-2022",
      "source": "https://trungtamwto.vn/thi-truong-duc/21143-sau-rieng-viet-nam-xuat-khau-chinh-ngach-sang-trung-quoc",
      "base_rate": 0.02,
      "risk_score": 1,
      "rate": 0.02,
      "factors": {
        "clean_history": false,
        "override_share": 0.0234,
        "high_overrides": false,
        "over_quota": false,
        "low_headroom": false
      }
    },
    "population": 123,
    "sample_count": 3,
    "analytes": [
      "cadmium",
      "auramine_o"
    ],
    "selected_by": "operator@coop.example",
    "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
  }
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/lots/{lot}/samples

Select a lot's samples and assign a lab

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · sampleLot

Takes no input: the system decides how many fruits are sampled, which ones and which lab tests them, so a tenant cannot pick the samples. Rule: the sampling rule of the lot's crop (its product) for its destination market, or the crop's only rule when the lot's destination names no market; a crop without one (or with rules for several markets and no destination naming one) is not sampled (409 no sampling rule). Durian has the China durian protocol. Count: the rule's rate (for durian, 2% of the consignment, the lot's export fruits; 1% after two years of the growing area without a failed sample) times a risk score from the deployment's sampling policy (sensory override share, the growing area's volume headroom), rounded up, at least 1 and at most 50. The fruits are drawn with a CSPRNG, and the lab the same way, only among the labs that serve the lot's company (#278: a platform admin links a lab to the companies it serves, linkLabCompany; a lab without a link serves no company); when no lab in force with an active key serves it, the lot is not sampled (409 no lab serves this company; 409 no accredited lab available when no lab is in force at all). D15 (#322): for a market whose official approved-lab list the deployment imports (AGRITRACE_LAB_LIST_MARKETS), the lab is drawn only among those labs whose current approvals for that market (valid today in Asia/Ho_Chi_Minh) together cover every analyte of the rule; when none does, the lot is not sampled (409 no approved lab available). For any other market the lab is drawn among every lab in force with an active key that serves the company, and the fallback is logged as a warning. Test scope: the rule's analytes (for durian, cadmium and auramine O). Needs a lot that is open, paused, closed or packed, with no open or paused measurement session, no fruit in review (pending_review) and, while the lot is open, none awaiting a device measurement (awaiting_device) (409 lot not settled otherwise, since a review decision or a late envelope could still move it into or out of the population; on a paused, closed or packed lot no envelope binds and no fruit action applies, so an unmeasured fruit is final and stays outside the population) and at least one export fruit; a lot is sampled once (a second request is 409, nothing is overwritten). The sampling freezes the lot's fruits: afterwards, even while the lot is open, a new measurement session on the lot and every fruit action on its fruits are 409 lot sampled, a device envelope for one of its fruits is stored but not bound (alert lot_sampled), and a review of an envelope bound to one of them changes only the envelope's status (alert lot_sampled), so the recorded population and the drawn fruits keep the state they were sampled in. The sample statuses change later with the lab's results. Audited (lot.sample, with how the lab was drawn: lab_draw approved_list or any_lab). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only the lots of its facilities).

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Idempotency-Key
không bắt buộc
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.

Phản hồi

Mã trạng tháiKiểuMô tả
201LotSampling
application/json

The new sampling.

400Error
application/json

Invalid JSON, any field in the body (sampling takes no input), a lot with more export fruits than the policy bound, 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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The lot cannot be sampled now. 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 201 · application/json
{
  "lot": "LO-260928-014",
  "lab": {
    "code": "LAB-VN-118",
    "name": "Phòng thử nghiệm mẫu"
  },
  "rule": {
    "id": "cn-durian-protocol-2022",
    "source": "https://trungtamwto.vn/thi-truong-duc/21143-sau-rieng-viet-nam-xuat-khau-chinh-ngach-sang-trung-quoc",
    "base_rate": 0.02,
    "risk_score": 1,
    "rate": 0.02,
    "factors": {
      "clean_history": false,
      "override_share": 0.0234,
      "high_overrides": false,
      "over_quota": false,
      "low_headroom": false
    }
  },
  "population": 123,
  "sample_count": 3,
  "analytes": [
    "cadmium",
    "auramine_o"
  ],
  "selected_by": "operator@coop.example",
  "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
}
Phản hồi 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
Phản hồi 400 · application/json · unknown_field
{
  "error": "unknown field: sampling takes no input",
  "code": "unknown_field"
}
Phản hồi 400 · application/json · too_large
{
  "error": "lot too large to sample: more than 50000 export fruits",
  "code": "lot_too_large_to_sample"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · sampled
{
  "error": "lot already sampled",
  "code": "lot_already_sampled"
}
Phản hồi 409 · application/json · measuring
{
  "error": "lot has an active measurement session",
  "code": "lot_has_an_active_measurement_session"
}
Phản hồi 409 · application/json · unsettled
{
  "error": "lot not settled: a fruit awaits a device measurement or a review; measure, reject or review it before sampling",
  "code": "lot_not_settled"
}
Phản hồi 409 · application/json · empty
{
  "error": "lot has no export fruits to sample",
  "code": "lot_has_no_export_fruits_to_sample"
}
Phản hồi 409 · application/json · status
{
  "error": "lot status draft does not allow sampling",
  "code": "lot_status_draft_does_not_allow_sampling"
}
Phản hồi 409 · application/json · no_lab
{
  "error": "no accredited lab available",
  "code": "no_accredited_lab_available"
}
Phản hồi 409 · application/json · no_lab_for_company
{
  "error": "no lab serves this company: none in force with an active key is linked to it; a platform admin links one",
  "code": "no_lab_serves_this_company"
}
Phản hồi 409 · application/json · no_approved_lab
{
  "error": "no approved lab available: none in force is approved for CN for cadmium, auramine_o today",
  "code": "no_approved_lab_available"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/{lot}/trust

Lot trust snapshot and history

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · getLotTrust

The lot's persisted trust (L8, #33): the current snapshot (null before the lot's first recompute): the displayed tier (after the seal and the holds), the tier its evidence earns alone, the status (on_hold while a hold is open or escalated, an open public report's included: #46, kind report), the seal (the tier frozen when the lot left open, with its time; null before), the engine's machine explanation (reason codes with parameters and every journey step's tier, reasons and evidence sources: no prose) and when it was computed; whether the lot is queued for a recompute; its latest recorded holds; and one page of its history, newest first (a row per change of the snapshot, with the cause: the audit action of the mutation that queued it, ingest, or migration). Every evidence-changing write queues its lots and the request recomputes them right after its commit; the periodic job recomputes the rest. Times are Unix seconds. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities). Not audited (a read).

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

cursor
không bắt buộc
querystring

next_cursor of the previous page of history.

limit
không bắt buộc
queryinteger

History page size, 1 to 200.

Phản hồi

Mã trạng tháiKiểuMô tả
200LotTrust
application/json

The lot's persisted trust.

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 lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "lot": "LO-260928-014",
  "snapshot": {
    "tier": "self_declared",
    "computed": "self_declared",
    "status": "normal",
    "sealed": {
      "tier": "self_declared",
      "at": 1790560800,
      "basis": "transition"
    },
    "explanation": {
      "reasons": [
        {
          "code": "limited_by_step",
          "params": {
            "step": "harvest",
            "tier": "self_declared"
          }
        },
        {
          "code": "limited_by_step",
          "params": {
            "step": "packing",
            "tier": "self_declared"
          }
        }
      ],
      "steps": [
        {
          "step": "registration",
          "tier": "cross_checked",
          "reasons": [
            {
              "code": "lab_evidence_absent",
              "params": {
                "evidence": "authority_certificate"
              }
            }
          ],
          "sources": [
            "signed_app",
            "registry"
          ]
        },
        {
          "step": "harvest",
          "tier": "self_declared",
          "reasons": [
            {
              "code": "no_signed_evidence",
              "params": {}
            }
          ],
          "sources": [
            "tenant_entry"
          ]
        },
        {
          "step": "measurement",
          "tier": "cross_checked",
          "reasons": [
            {
              "code": "lab_tier_not_applicable",
              "params": {}
            },
            {
              "code": "measurement_overrides_present",
              "params": {
                "count": 3
              }
            }
          ],
          "sources": [
            "signed_device",
            "scale",
            "volume_quota"
          ]
        },
        {
          "step": "packing",
          "tier": "self_declared",
          "reasons": [
            {
              "code": "no_signed_evidence",
              "params": {}
            }
          ],
          "sources": [
            "tenant_entry"
          ]
        }
      ]
    },
    "computed_at": 1790560800
  },
  "queued": false,
  "holds": [
    {
      "id": 4,
      "kind": "quarantine",
      "status": "resolved",
      "opened_at": 1790474400,
      "closed_at": 1790478000
    }
  ],
  "history": [
    {
      "id": 12,
      "tier": "self_declared",
      "computed": "self_declared",
      "status": "normal",
      "sealed_tier": "self_declared",
      "cause": "lot.seal",
      "computed_at": 1790560800
    }
  ],
  "next_cursor": null
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/lots/{lot}/close

Close and digitally sign a lot (sealed manifest)

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · closeLot

Closes a draft or open lot (its open or paused measurement sessions are closed and its closed_at set, as a lot close does) and signs the lot's manifest with the active issuer key of its facility (L9: did:web) as a VC-JOSE credential (see LotSeal), in one transaction that also takes the lot's trust seal (the tier frozen when the lot leaves open; already taken for a packed or shipped lot) and writes the audit row. A closed, packed or shipped lot is signed without a status change, so a lot signed after its departure carries its packing and shipping. The manifest is what was recorded at the seal time; afterwards a review of an envelope bound to one of its fruits changes the envelope's status only (alert lot_sealed). A lot is signed once. Refused with 409 when the confirmed fruit count differs from the lot's, a fruit is in review (pending_review), the lot is recalled or withdrawn or already sealed, the facility has no active issuer key, or the manifest would list more than 5,000 fruits or 20,000 envelopes; 503 without a key-encryption key. Audited (lot.close: the key id, the manifest hash and the counts; never the credential). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only within its facilities); auditor and lab are refused.

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Idempotency-Key
không bắt buộc
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.

Nội dung yêu cầu

LotCloseRequest (bắt buộc)

Kiểu nội dung: application/json

Ví dụ yêu cầu · application/json
{
  "confirm_counts": {
    "fruits": 128
  }
}

Phản hồi

Mã trạng tháiKiểuMô tả
201LotSeal
application/json

The lot's seal.

400Error
application/json

Invalid JSON, a body other than exactly confirm_counts.fruits, 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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The lot cannot be signed: see the description. 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

No key-encryption key is configured (AGRITRACE_ISSUER_KEK), or the issuer key store cannot be used; nothing changed.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 201 · application/json
{
  "lot": "LO-260928-014",
  "status": "shipped",
  "sealed_at": 1790754000,
  "sealed_by": "user-12",
  "key_id": "did:web:txng.theio.vn:tanphu#key-1",
  "manifest_sha256": "a869373f50f23727be3ef525863a48347c2c7d057119b62e02076adaa472d617",
  "fruit_count": 128,
  "event_count": 397,
  "credential": "eyJhbGciOiJFUzI1NiIsImN0eSI6InZjIiwia2lkIjoiZGlkOndlYjp0eG5nLnRoZWlvLnZuOnRhbnBodSNrZXktMSIsInR5cCI6InZjK2p3dCJ9.eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvbnMvY3JlZGVudGlhbHMvdjIiXSwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJ1cm46YWdyaXRyYWNlOmxvdDozZjljMmE3YmU0MWQ0YzBhOWU4YjZkNWYxYTJjM2I0ZCIsImxvdCI6eyJjb2RlIjoiTE8tMjYwOTI4LTAxNCJ9fSwiaWQiOiJ1cm46YWdyaXRyYWNlOmxvdC1zZWFsOjNmOWMyYTdiZTQxZDRjMGE5ZThiNmQ1ZjFhMmMzYjRkIiwiaXNzdWVyIjoiZGlkOndlYjp0eG5nLnRoZWlvLnZuOnRhbnBodSIsInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJBZ3JpVHJhY2VMb3RTZWFsIl0sInZhbGlkRnJvbSI6IjIwMjYtMDktMzBUMDc6NDA6MDBaIn0.kctQ5XyOhXmF4wAaMoRTYUURRmG5IFU2VbzNcoaa483PwGtJks5WlZMAGrcxteF8ryX2IaBEaL_wgq8vWqCWIw"
}
Phản hồi 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
Phản hồi 400 · application/json · unknown_field
{
  "error": "unknown field: note",
  "code": "unknown_field"
}
Phản hồi 400 · application/json · confirm_counts
{
  "error": "confirm_counts.fruits must be a non-negative integer",
  "code": "confirm_counts_fruits_must_be_a_non_negative_integer"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · counts_changed
{
  "error": "counts changed: the lot has 128 fruits",
  "code": "counts_changed"
}
Phản hồi 409 · application/json · fruits_in_review
{
  "error": "fruits in review: 2",
  "code": "fruits_in_review"
}
Phản hồi 409 · application/json · already_sealed
{
  "error": "lot already sealed",
  "code": "lot_already_sealed"
}
Phản hồi 409 · application/json · invalid_transition
{
  "error": "invalid transition: recalled to sealed",
  "code": "invalid_transition"
}
Phản hồi 409 · application/json · no_active_issuer_key
{
  "error": "no active issuer key: facility VN-TGPH-021",
  "code": "no_active_issuer_key"
}
Phản hồi 409 · application/json · too_large
{
  "error": "lot too large to seal: more than 5000 fruits",
  "code": "lot_too_large_to_seal"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}
Phản hồi 503 · application/json
{
  "error": "issuer keys unavailable: AGRITRACE_ISSUER_KEK is not configured",
  "code": "issuer_keys_unavailable"
}

GET /v1/lots/{lot}/manifest

A lot's signed seal

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · getLotManifest

The lot's seal (L10, #35): the signed credential of its manifest, its hash, the signing key and the counts (see LotSeal); 404 while the lot is not sealed. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities). Not audited (a read).

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Phản hồi

Mã trạng tháiKiểuMô tả
200LotSeal
application/json

The lot's seal.

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 lot for this tenant (a lot of another tenant, or of a facility outside an operator's facilities, answers exactly like a missing one), or the lot is not sealed.

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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "lot": "LO-260928-014",
  "status": "shipped",
  "sealed_at": 1790754000,
  "sealed_by": "user-12",
  "key_id": "did:web:txng.theio.vn:tanphu#key-1",
  "manifest_sha256": "a869373f50f23727be3ef525863a48347c2c7d057119b62e02076adaa472d617",
  "fruit_count": 128,
  "event_count": 397,
  "credential": "eyJhbGciOiJFUzI1NiIsImN0eSI6InZjIiwia2lkIjoiZGlkOndlYjp0eG5nLnRoZWlvLnZuOnRhbnBodSNrZXktMSIsInR5cCI6InZjK2p3dCJ9.eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvbnMvY3JlZGVudGlhbHMvdjIiXSwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJ1cm46YWdyaXRyYWNlOmxvdDozZjljMmE3YmU0MWQ0YzBhOWU4YjZkNWYxYTJjM2I0ZCIsImxvdCI6eyJjb2RlIjoiTE8tMjYwOTI4LTAxNCJ9fSwiaWQiOiJ1cm46YWdyaXRyYWNlOmxvdC1zZWFsOjNmOWMyYTdiZTQxZDRjMGE5ZThiNmQ1ZjFhMmMzYjRkIiwiaXNzdWVyIjoiZGlkOndlYjp0eG5nLnRoZWlvLnZuOnRhbnBodSIsInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJBZ3JpVHJhY2VMb3RTZWFsIl0sInZhbGlkRnJvbSI6IjIwMjYtMDktMzBUMDc6NDA6MDBaIn0.kctQ5XyOhXmF4wAaMoRTYUURRmG5IFU2VbzNcoaa483PwGtJks5WlZMAGrcxteF8ryX2IaBEaL_wgq8vWqCWIw"
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json · not_found
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 404 · application/json · not_sealed
{
  "error": "lot not sealed",
  "code": "lot_not_sealed"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/{lot}/close-check

A lot's close check

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · getLotCloseCheck

What the operator console's close dialog shows (O6, #64) before POST /v1/lots/{lot}/close and after it: the final counts, the measurement sessions still open or paused, the facility's active issuer key, the blockers (codes, in this order: already_sealed, not_sealable, fruits_pending_review, session_open, envelopes_not_synced, no_issuer_key, lot_too_large) and, once sealed, the seal with its external timestamp state. The close itself checks again what it refuses: the check is a view, not a lock. Seven statements whatever the lot's size. Allowed for platform_admin, tenant_admin and auditor (the whole tenant) and for an operator signed in with a session (only the lots of its facilities). Not audited (a read).

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Phản hồi

Mã trạng tháiKiểuMô tả
200LotCloseCheck
application/json

The lot's close check.

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 lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "lot": "LO-260928-014",
  "status": "open",
  "sealed": false,
  "counts": {
    "fruits": 128,
    "pending_review": 0,
    "awaiting_device": 1,
    "quarantined_envelopes": 0,
    "cartons": null
  },
  "sessions": {
    "open": 1,
    "paused": 0
  },
  "issuer_key": "did:web:txng.theio.vn:tanphu#key-1",
  "timestamping": true,
  "blockers": [
    "session_open",
    "envelopes_not_synced"
  ],
  "seal": null
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/lots/{lot}/recall

Recall or withdraw a lot (terminal)

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_recall · recallLot

Recalls (recalled) or withdraws (withdrawn) the whole lot (P5, #41; domain model, State Machines: exceptional terminal public states). In one transaction under the lot's lock: its open or paused measurement sessions close, its status changes, the recall is stored with the state the lot left and the trace counts, an outbound notice is stored for the outbound adapter (#90, pending: nothing is sent), the lot's trust seal is taken when it had none, and the audit row is written (lot.recall: the prior and new status, kind, reason, scope and counts; never the note). Nothing is deleted: the lot keeps its history and stays public when it was. The public lot and fruit records then show status recalled or withdrawn from the recall time with status_reason, and a displayed tier of Self-declared for good (reason lot_recalled). Packing and shipping refuse the lot, and a shipment carrying it cannot depart. There is no reversal: a second recall or withdrawal is refused with 409. Allowed for tenant_admin and platform_admin acting for the tenant; another tenant's lot answers like a missing one. 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.

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Idempotency-Key
không bắt buộc
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.

Nội dung yêu cầu

LotRecallRequest (bắt buộc)

Kiểu nội dung: application/json

Ví dụ yêu cầu · application/json
{
  "kind": "recall",
  "reason": "contamination",
  "scope": "consumer",
  "note": "Cadmium over the CN limit in the lab's re-test."
}

Phản hồi

Mã trạng tháiKiểuMô tả
201LotTrace
application/json

The lot's trace with its recall.

400Error
application/json

Invalid JSON, an unknown field, a kind, reason or scope outside the enums, a note over 1,000 characters, 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 (only tenant_admin and platform_admin), 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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

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.

409Error
application/json

The lot is already recalled or withdrawn (both are terminal). 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 201 · application/json
{
  "lot": {
    "code": "LO-260928-014",
    "status": "recalled",
    "product": "durian",
    "variety": "Ri6",
    "public_id": "5d0c7a3e9b1f4a2c8e6d0b4f7a9c3e1d"
  },
  "recall": {
    "kind": "recall",
    "status": "recalled",
    "reason": "contamination",
    "scope": "consumer",
    "note": "Cadmium over the CN limit in the lab's re-test.",
    "prior_status": "shipped",
    "recalled_by": "user-7",
    "recalled_at": 1790010000,
    "cartons": 2,
    "shipments": 1,
    "notice": {
      "target": "national_portal",
      "status": "pending",
      "attempts": 0,
      "created_at": 1790010000,
      "delivered_at": null
    }
  },
  "backward": {
    "facility": {
      "code": "VN-TGPH-021",
      "name": "Tân Phú"
    },
    "growing_area": {
      "code": "VN-TGOR-0387",
      "commune": "Ngũ Hiệp",
      "district": "Cai Lậy",
      "province": "Tiền Giang"
    },
    "harvest": {
      "date": "2026-09-27",
      "at": 1790470000,
      "kg": 500,
      "source": "signed_event"
    }
  },
  "forward": {
    "cartons": {
      "count": 2,
      "fruits": 5,
      "net_mass_kg": 14.37,
      "truncated": false,
      "items": [
        {
          "code": "C-0928014-0001",
          "carton_no": 1,
          "fruits": 3,
          "net_mass_kg": 8.6,
          "shipment": "SH-260930-01"
        },
        {
          "code": "C-0928014-0002",
          "carton_no": 2,
          "fruits": 2,
          "net_mass_kg": 5.77,
          "shipment": "SH-260930-01"
        }
      ]
    },
    "shipment": {
      "code": "SH-260930-01",
      "facility": "VN-TGPH-021",
      "status": "departed",
      "container": "CSQU3054383",
      "destination": "CN",
      "border_gate": "Hữu Nghị",
      "departed_at": 1790722800,
      "cartons": 2
    }
  },
  "related_lots": {
    "items": [
      {
        "code": "LO-260928-015",
        "status": "packed",
        "harvest_date": "2026-09-27"
      }
    ],
    "truncated": false
  }
}
Phản hồi 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
Phản hồi 400 · application/json · unknown
{
  "error": "unknown fields: by",
  "code": "unknown_fields"
}
Phản hồi 400 · application/json · kind
{
  "error": "invalid kind: recall or withdrawal",
  "code": "invalid_kind"
}
Phản hồi 400 · application/json · reason
{
  "error": "invalid reason: one of contamination, pathogen, foreign_matter, labelling, quality, regulatory, traceability, other",
  "code": "invalid_reason"
}
Phản hồi 400 · application/json · scope
{
  "error": "invalid scope: one of consumer, retail, wholesale",
  "code": "invalid_scope"
}
Phản hồi 400 · application/json · note
{
  "error": "invalid note: a string of at most 1000 characters",
  "code": "invalid_note"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · terminal
{
  "error": "lot is terminal: recalled",
  "code": "lot_is_terminal"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/{lot}/trace

Trace a lot forward and back (the affected set of a recall)

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: recall_read · getLotTrace

The lot's affected set (P5, #41; see LotTrace), whether or not it is recalled: a read with a fixed number of statements, not audited, never cached (Cache-Control: no-store). Allowed for tenant_admin, platform_admin acting for the tenant and auditor (staff only); operators and labs are refused; another tenant's lot answers like a missing one. With merges=1 the trace also names the lots its chain of lot merges links (#259): the lots the chain produced from this one (forward.merged_into), the input lots of the merge that produced this one (backward.merged_from) and the lot of each listed carton (forward.cartons.items[].lot); without it those fields are absent and the trace reads as before. The parameter and the fields are not part of the partner SDK clients (x-not-in-sdk): SDK 0.3.0 was released before them, and its clients refuse a field they do not know.

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

merges
không bắt buộc
query"0" | "1"

1 adds the lots the chain of merges links (forward.merged_into, backward.merged_from, forward.cartons.items[].lot); 0 or none leaves them out; any other value is refused (400 bad merges).

Phản hồi

Mã trạng tháiKiểuMô tả
200LotTrace
application/json

The lot's trace.

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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "lot": {
    "code": "LO-260928-014",
    "status": "recalled",
    "product": "durian",
    "variety": "Ri6",
    "public_id": "5d0c7a3e9b1f4a2c8e6d0b4f7a9c3e1d"
  },
  "recall": {
    "kind": "recall",
    "status": "recalled",
    "reason": "contamination",
    "scope": "consumer",
    "note": "Cadmium over the CN limit in the lab's re-test.",
    "prior_status": "shipped",
    "recalled_by": "user-7",
    "recalled_at": 1790010000,
    "cartons": 2,
    "shipments": 1,
    "notice": {
      "target": "national_portal",
      "status": "pending",
      "attempts": 0,
      "created_at": 1790010000,
      "delivered_at": null
    }
  },
  "backward": {
    "facility": {
      "code": "VN-TGPH-021",
      "name": "Tân Phú"
    },
    "growing_area": {
      "code": "VN-TGOR-0387",
      "commune": "Ngũ Hiệp",
      "district": "Cai Lậy",
      "province": "Tiền Giang"
    },
    "harvest": {
      "date": "2026-09-27",
      "at": 1790470000,
      "kg": 500,
      "source": "signed_event"
    }
  },
  "forward": {
    "cartons": {
      "count": 2,
      "fruits": 5,
      "net_mass_kg": 14.37,
      "truncated": false,
      "items": [
        {
          "code": "C-0928014-0001",
          "carton_no": 1,
          "fruits": 3,
          "net_mass_kg": 8.6,
          "shipment": "SH-260930-01"
        },
        {
          "code": "C-0928014-0002",
          "carton_no": 2,
          "fruits": 2,
          "net_mass_kg": 5.77,
          "shipment": "SH-260930-01"
        }
      ]
    },
    "shipment": {
      "code": "SH-260930-01",
      "facility": "VN-TGPH-021",
      "status": "departed",
      "container": "CSQU3054383",
      "destination": "CN",
      "border_gate": "Hữu Nghị",
      "departed_at": 1790722800,
      "cartons": 2
    }
  },
  "related_lots": {
    "items": [
      {
        "code": "LO-260928-015",
        "status": "packed",
        "harvest_date": "2026-09-27"
      }
    ],
    "truncated": false
  }
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/recalls

The company's recalls and withdrawals

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: recall_read · listRecalls

#322: the company's lot recalls and withdrawals, newest first (at most 100), each with its lot code, the recall (LotRecall: kind, reason category, scope, staff note, the state the lot left, the opaque operator id, the time, the cartons and shipments the trace found) and its outbound notice for the national portal, stored and not sent yet (pending) until the outbound adapter delivers it; total counts every recall and withdrawal of the company and notices_pending their notices not sent yet. Never cached (Cache-Control: no-store). Allowed for tenant_admin, platform_admin acting for the tenant and auditor (staff only); operators and labs are refused. Not audited (a read). Not part of the partner SDK clients (x-not-in-sdk): SDK 0.2.0 was released before it.

Phản hồi

Mã trạng tháiKiểuMô tả
200RecallList
application/json

The company's recalls and withdrawals.

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

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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "items": [
    {
      "lot": "LO-260928-014",
      "recall": {
        "kind": "recall",
        "status": "recalled",
        "reason": "contamination",
        "scope": "consumer",
        "note": "",
        "prior_status": "shipped",
        "recalled_by": "user-12",
        "recalled_at": 1790700000,
        "cartons": 41,
        "shipments": 1,
        "notice": {
          "target": "national_portal",
          "status": "pending",
          "attempts": 0,
          "created_at": 1790700000,
          "delivered_at": null
        }
      }
    }
  ],
  "total": 1,
  "notices_pending": 1
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/grading-rules/{variety}/history

The versions of a variety's grading rules

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: grading_rule_read · getGradingRuleHistory

Every version the caller's tenant stored for the variety, newest first, one page (limit, default 20, at most 50; cursor from the previous page). A variety the tenant has no rules for is a 404 (it is graded with the platform default). Allowed for platform_admin, tenant_admin and auditor; operators and lab are refused. Not audited (a read).

Tham số

TênVị tríKiểuMô tả
variety
bắt buộc
pathstring

Lot variety (1 to 64 characters), as on the lot.

limit
không bắt buộc
queryinteger

1 to 50 (default 20).

cursor
không bắt buộc
querystring

The previous page's next_cursor.

Phản hồi

Mã trạng tháiKiểuMô tả
200GradingRuleHistory
application/json

One page of versions.

400Error
application/json

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

404Error
application/json

The tenant has no rules for this variety.

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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "variety": "Ri6",
  "items": [
    {
      "version": 2,
      "rules": {
        "a_levels": [
          2,
          3
        ],
        "reject_levels": [
          1,
          4
        ],
        "a_weight_kg": [
          [
            2,
            5
          ]
        ],
        "a_min_confidence": 0.8,
        "eating_window": [
          {
            "band": "ambient",
            "end_days": 7,
            "level": 1,
            "max_days": 30,
            "min_days": 0,
            "start_days": 5,
            "warning": "immature"
          },
          {
            "band": "ambient",
            "end_days": 6,
            "level": 2,
            "max_days": 1,
            "min_days": 0,
            "start_days": 4,
            "warning": null
          },
          {
            "band": "ambient",
            "end_days": 4,
            "level": 2,
            "max_days": 3,
            "min_days": 2,
            "start_days": 3,
            "warning": null
          },
          {
            "band": "ambient",
            "end_days": 2,
            "level": 2,
            "max_days": 30,
            "min_days": 4,
            "start_days": 1,
            "warning": "eat_soon"
          },
          {
            "band": "ambient",
            "end_days": 4,
            "level": 3,
            "max_days": 1,
            "min_days": 0,
            "start_days": 3,
            "warning": null
          },
          {
            "band": "ambient",
            "end_days": 3,
            "level": 3,
            "max_days": 3,
            "min_days": 2,
            "start_days": 2,
            "warning": null
          },
          {
            "band": "ambient",
            "end_days": 1,
            "level": 3,
            "max_days": 30,
            "min_days": 4,
            "start_days": 0,
            "warning": "eat_soon"
          },
          {
            "band": "ambient",
            "end_days": 1,
            "level": 4,
            "max_days": 30,
            "min_days": 0,
            "start_days": 0,
            "warning": "overripe"
          },
          {
            "band": "14-18C",
            "end_days": 10,
            "level": 1,
            "max_days": 30,
            "min_days": 0,
            "start_days": 7,
            "warning": "immature"
          },
          {
            "band": "14-18C",
            "end_days": 8,
            "level": 2,
            "max_days": 30,
            "min_days": 0,
            "start_days": 5,
            "warning": null
          },
          {
            "band": "14-18C",
            "end_days": 6,
            "level": 3,
            "max_days": 30,
            "min_days": 0,
            "start_days": 4,
            "warning": null
          },
          {
            "band": "14-18C",
            "end_days": 2,
            "level": 4,
            "max_days": 30,
            "min_days": 0,
            "start_days": 0,
            "warning": "overripe"
          },
          {
            "band": "10-13C",
            "end_days": 12,
            "level": 1,
            "max_days": 30,
            "min_days": 0,
            "start_days": 9,
            "warning": "immature"
          },
          {
            "band": "10-13C",
            "end_days": 10,
            "level": 2,
            "max_days": 30,
            "min_days": 0,
            "start_days": 7,
            "warning": null
          },
          {
            "band": "10-13C",
            "end_days": 8,
            "level": 3,
            "max_days": 30,
            "min_days": 0,
            "start_days": 5,
            "warning": null
          },
          {
            "band": "10-13C",
            "end_days": 2,
            "level": 4,
            "max_days": 30,
            "min_days": 0,
            "start_days": 0,
            "warning": "overripe"
          }
        ]
      },
      "updated_at": 1790000000.5,
      "updated_by": "admin@coop.example"
    }
  ],
  "next_cursor": null
}
Phản hồi 400 · application/json · variety
{
  "error": "invalid variety: a string of 1 to 64 characters",
  "code": "invalid_variety"
}
Phản hồi 400 · application/json · limit
{
  "error": "bad limit",
  "code": "bad_limit"
}
Phản hồi 400 · application/json · cursor
{
  "error": "bad cursor",
  "code": "bad_cursor"
}
Phản hồi 400 · application/json · bad_request_id
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: Ri6",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/sessions/{id}/fruits/batch

Allocate up to 1,000 fruits of a session

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · allocateFruitBatch

Allocates count fruits of an open measurement session (consecutive n of its lot) with their label payloads, to print labels ahead of the line: a batch issues no set_session command to the session's devices. Audited once (fruit.batch_allocate). Allowed like the single allocation. Atomic: the batch commits whole or not at all, in one transaction with its one audit row. Every item is validated first and every invalid item is reported (400 invalid_batch, items by index); then the items are applied in order and the first one the stored state refuses rolls the batch back and is reported (batch_rejected with the item's own status and items naming it). At most 1,000 items and a body within 1 MiB. #326: with label_code=1 each label payload also has the fruit's lookup code (label_code, #288), the 15-character code a label prints beside the QR code for a person whose QR code cannot be scanned; the scan page and GET /v1/public/resolve read it. Rate limited per tenant and caller (bursts of 10 batches, then one every 6 seconds).

Tham số

TênVị tríKiểuMô tả
id
bắt buộc
pathstring

Measurement session id.

Idempotency-Key
không bắt buộc
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.

label_code
không bắt buộc
query"0" | "1"

#326: 1 adds each fruit's lookup code to its label payload (items[].label.label_code); 0 or none leaves it out and answers exactly as before; any other value is refused (400 bad label_code).

Nội dung yêu cầu

BatchCount (bắt buộc)

Kiểu nội dung: application/json

Ví dụ yêu cầu · application/json
{
  "count": 200
}

Phản hồi

Mã trạng tháiKiểuMô tả
201FruitBatchResult
application/json

The batch, committed.

400Error
application/json

Invalid JSON, a body of the wrong shape, invalid items (invalid_batch, each one listed), an item the stored state refuses as invalid (batch_rejected) or a bad X-Request-Id; a malformed or repeated Idempotency-Key header; or label_code not 0 or 1.

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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such measurement session for this tenant: a session of another tenant, or of a facility outside an operator's scope, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The session's lot is past open, or the session is paused or closed; or the Idempotency-Key's batch was applied more than 24 hours ago (its response is no longer stored) for this route, path id and body. 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 before with another request (another method, path, query or body): idempotency_key_mismatch within 24 hours, idempotency_key_reused_with_a_different_request for a batch key older than that; nothing was done.

429Error
application/json

Too many batch requests from this caller of this tenant (bursts of 10, then one every 6 seconds); nothing was done; retry after Retry-After seconds.

500Error
application/json

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

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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-Id429string

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

Seconds to wait before retrying.

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.

Ví dụ phản hồi

Phản hồi 201 · application/json
{
  "batch_id": 12,
  "count": 1,
  "items": [
    {
      "tenant": "coop-dl",
      "code": "Q-014-0129",
      "n": 129,
      "public_id": "5f0c9a1e7b2d4c3a8e6f1b0d9c7a2e4f",
      "lot": "LO-260928-014",
      "session": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
      "line": "A2",
      "operator": "user-7",
      "status": "awaiting_device",
      "labels_printed_at": 1790000000.5,
      "created_at": 1790000000.5,
      "updated_at": 1790000000.5,
      "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7",
      "label": {
        "code": "Q-014-0129",
        "lot": "LO-260928-014",
        "n": 129,
        "line": "A2",
        "operator": "user-7",
        "printed_at": 1790000000.5,
        "qr_url": "https://txng.theio.vn/01/00012345678905/10/LO-260928-014/21/k3Vd9_Qe2LmXa0Zr-Tb7"
      },
      "level": null,
      "level_pred": null,
      "maturity_class": null,
      "confidence": null,
      "model": null,
      "measured_at": null,
      "weight_kg": null,
      "level_sensory": null,
      "override": false,
      "pending_review": false,
      "grade": null,
      "eating_window": null,
      "record_tier": null,
      "knock_envelope_id": null,
      "scale_envelope_id": null,
      "override_envelope_id": null
    }
  ]
}
Phản hồi 400 · application/json · invalid_batch
{
  "error": "invalid batch: 1 of the items failed validation",
  "code": "invalid_batch",
  "items": [
    {
      "index": 3,
      "status": 400,
      "error": "invalid kg: a number above 0 and at most 1000000",
      "code": "invalid_kg"
    }
  ]
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 400 · application/json · bad_label_code
{
  "error": "bad label_code",
  "code": "bad_label_code"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: ms-3c1f",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · session_is_closed
{
  "error": "session is closed",
  "code": "session_is_closed"
}
Phản hồi 409 · application/json · idempotency_key_already_used
{
  "error": "idempotency key already used: batch 12",
  "code": "idempotency_key_already_used"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 422 · application/json · idempotency_key_mismatch
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 422 · application/json · idempotency_key_reused_with_a_different_request
{
  "error": "idempotency key reused with a different request",
  "code": "idempotency_key_reused_with_a_different_request"
}
Phản hồi 429 · application/json
{
  "error": "too many requests",
  "code": "too_many_requests"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/console/home

Read the console's work home

Xác thực: cookie · getConsoleHome

Chỉ dùng phiên đăng nhập — API token và ứng dụng OAuth không gọi được

#286. For the selected company (X-Tenant) and the caller's packing houses: the work home of the console. The open and paused measurement sessions (with whether the caller opened each), the work by next action (lots to measure, to close and sign, with a failed lab result, waiting for the lab, to pack and seal, to label for export, to put on a shipment, recalled in the last 30 days; counted among the newest 1,000 lots of each packing house, work.window), the open shipments, the device messages waiting for review, the devices and stations, and today's counts in the Vietnam calendar day. An operator's answer holds only the packing houses of their role (every one of the company when their role names none); a company admin's, and a platform admin's acting for the company, the whole company. Computed at most every 10 seconds per company and set of packing houses: the server serves one answer for max_age_s seconds after generated_at. Read-only and not audited (a read). no-store. Allowed for tenant_admin, platform_admin (acting for the company through X-Tenant) and operator through a signed-in session only: an API token, an API client or the legacy token is refused (403); auditors and lab users are refused (403). Not part of the partner SDK clients (x-not-in-sdk): an operation of the console's work home.

Phản hồi

Mã trạng tháiKiểuMô tả
200ConsoleHome
application/json

The work 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 tenant_admin, platform_admin and operator, through a signed-in session: an API token, an API client or the legacy token is refused; auditors and lab users are refused), tenant not allowed (X-Tenant), two-factor required (this session must prove a second factor before acting for the company).

404Error
application/json

No such company: a platform admin named one (X-Tenant) that does not exist.

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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "tenant": "coop-dl",
  "generated_at": "2026-10-18T02:12:40Z",
  "max_age_s": 10,
  "day": {
    "date": "2026-10-18",
    "starts_at": "2026-10-17T17:00:00Z",
    "time_zone": "Asia/Ho_Chi_Minh"
  },
  "scope": {
    "all_facilities": false,
    "facilities": [
      {
        "code": "VN-TGPH-021",
        "name": "Tân Phú",
        "lines": [
          "A1",
          "A2",
          "B1"
        ]
      }
    ]
  },
  "sections": {
    "sessions": {
      "state": "ok",
      "total": 1,
      "items": [
        {
          "id": "3b1f6c2e-8a4d-4f0b-9c7e-2d5a1b8e6f30",
          "lot": "LO-260928-014",
          "variety": "Ri6",
          "facility": "VN-TGPH-021",
          "line": "A2",
          "status": "open",
          "opened_at": "2026-10-18T00:42:00Z",
          "paused_at": null,
          "fruits": 128,
          "opened_by_you": true
        }
      ]
    },
    "work": {
      "state": "ok",
      "window": {
        "per_facility": 1000,
        "full": false
      },
      "tasks": {
        "measure": {
          "count": 1,
          "oldest": [
            {
              "code": "LO-261018-002",
              "facility": "VN-TGPH-021",
              "since": "2026-10-18T01:05:00Z"
            }
          ]
        },
        "close": {
          "count": 0,
          "oldest": []
        },
        "sample": {
          "count": 0,
          "oldest": []
        },
        "lab_failed": {
          "count": 0,
          "oldest": []
        },
        "lab_waiting": {
          "count": 1,
          "oldest": [
            {
              "code": "LO-260927-009",
              "facility": "VN-TGPH-021",
              "since": "2026-10-17T09:30:00Z"
            }
          ]
        },
        "pack": {
          "count": 1,
          "oldest": [
            {
              "code": "LO-260927-011",
              "facility": "VN-TGPH-021",
              "since": "2026-10-17T10:20:00Z"
            }
          ]
        },
        "label": {
          "count": 0,
          "oldest": []
        },
        "ship": {
          "count": 1,
          "oldest": [
            {
              "code": "LO-260926-004",
              "facility": "VN-TGPH-021",
              "since": "2026-10-16T08:00:00Z"
            }
          ]
        },
        "recalled": {
          "count": 0,
          "oldest": []
        }
      }
    },
    "shipments": {
      "state": "ok",
      "open": 1,
      "items": [
        {
          "code": "SH-260930-01",
          "facility": "VN-TGPH-021",
          "lots": 2,
          "logger_check": "missing",
          "created_at": "2026-10-17T08:00:00Z"
        }
      ],
      "logger_missing": {
        "count": 0,
        "oldest": []
      }
    },
    "review": {
      "state": "ok",
      "quarantined": 0,
      "capped": false,
      "oldest_received_at": null
    },
    "devices": {
      "state": "ok",
      "total": 1,
      "capped": false,
      "items": [
        {
          "device_id": "sf100-0417",
          "name": "SF-100",
          "facility": "VN-TGPH-021",
          "measures": true,
          "approval": "approved",
          "ready": true,
          "last_seen": "2026-10-18T02:11:58Z",
          "calibration_valid_until": "2026-11-15T00:00:00Z"
        }
      ],
      "gateways": [
        {
          "gateway_id": "gw-tp-01",
          "name": "Station Tân Phú",
          "facility": "VN-TGPH-021",
          "last_heartbeat": "2026-10-18T02:11:00Z",
          "silent": false
        }
      ],
      "gateways_capped": false
    },
    "today": {
      "state": "ok",
      "lots_created": 2,
      "lots_closed": 1,
      "lots_packed": 0,
      "shipments_departed": 0,
      "messages": 5123,
      "messages_capped": false
    }
  }
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · two_factor
{
  "error": "two-factor required: set up two-step sign-in for this account",
  "code": "two_factor_required"
}
Phản hồi 404 · application/json
{
  "error": "not found: company",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

POST /v1/lots/{lot}/merge

Record a lot merge producing this lot

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_write · mergeLots

#91: records that the path's lot (the output) was produced by merging 2 to 50 other lots of the caller's tenant (the inputs), each with the kilograms taken from it: the transform event type of the event types vocabulary 1.2.0 (/developers/downloads/event-types-v1.json), FSMA 204's transformation CTE. The output must be a draft lot without cartons, produced by no earlier merge; each input closed, packed or shipped, of the output's product, never merged before and not on hold. Mass balance: output_kg may differ from the sum of the inputs' quantity_kg by at most 5 % of that sum, and a packed input gives at most its packed net mass plus 5 %. The merge happens at the output lot's facility and changes no lot's status. Trust (ADR 0001): the output's tier is at most the lowest displayed tier of its inputs (reason limited_by_input), so a merge never raises a tier. The merge is a TransformationEvent in the staff EPCIS document (GET /v1/lots/{lot}/epcis) and rows of the records export of each of its lots. Tenant-entered. Audited (lot.merge). Allowed for platform_admin and tenant_admin (the whole tenant) and for an operator signed in with a session (only within its facilities, for the output and every input); auditor and lab are refused. Not part of the partner SDK clients (x-not-in-sdk): SDK 0.2.0 was released before it.

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Idempotency-Key
không bắt buộc
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.

Nội dung yêu cầu

LotMergeRequest (bắt buộc)

Kiểu nội dung: application/json

Ví dụ yêu cầu · application/json
{
  "inputs": [
    {
      "lot": "LO-260928-014",
      "quantity_kg": 349.6
    },
    {
      "lot": "LO-260929-002",
      "quantity_kg": 120.4
    }
  ],
  "output_kg": 468.5
}

Phản hồi

Mã trạng tháiKiểuMô tả
201LotTransformation
application/json

The merge as recorded.

400Error
application/json

Invalid JSON, a body that is not exactly inputs and output_kg, a bad input (not 2 to 50 distinct lot codes, the output lot itself, a quantity that is not a number of kilograms), a product mismatch, a mass balance violation (output_kg differs from the inputs' sum by more than 5 %, a quantity not above 0 or above 1 000 000 kg, or a packed input giving more than its packed net mass plus 5 %), 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 while the company is leaving CropPath or has left (its records can be read and exported, not changed).

404Error
application/json

No such lot for this tenant, for the output lot or any input: a lot of another tenant, or of a facility outside an operator's facilities, answers exactly like a missing one.

405Error
application/json

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

409Error
application/json

The output lot is not a draft lot without cartons, names a growing area or harvest of its own (lot_has_own_origin: a merged lot takes its origin from its inputs) or was already produced by a merge; or an input is not closed, packed or shipped, was already merged or is on hold (an open or escalated hold); or the merge would make the chain of merges deeper than a recall follows (merge_chain_too_deep: an input already 8 merges deep, or more than 64 merges behind the merged lot in all). 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 201 · application/json
{
  "event_id": "6f1c2a9e-3b7d-4c55-9a51-0d2e8f4b7c13",
  "lot": "LO-261002-031",
  "facility": "VN-TGPH-021",
  "inputs": [
    {
      "lot": "LO-260928-014",
      "quantity_kg": 349.6
    },
    {
      "lot": "LO-260929-002",
      "quantity_kg": 120.4
    }
  ],
  "input_kg": 470,
  "output_kg": 468.5,
  "mass_tolerance": 0.05,
  "recorded_at": 1790090000
}
Phản hồi 400 · application/json · invalid_json
{
  "error": "invalid JSON",
  "code": "invalid_json"
}
Phản hồi 400 · application/json · invalid_body
{
  "error": "invalid body: give inputs and output_kg",
  "code": "invalid_body"
}
Phản hồi 400 · application/json · invalid_inputs
{
  "error": "invalid inputs: 2 to 50 lots",
  "code": "invalid_inputs"
}
Phản hồi 400 · application/json · mass_balance
{
  "error": "mass balance: output_kg 600 differs from the inputs' 470 kg by more than 5%",
  "code": "mass_balance"
}
Phản hồi 400 · application/json · product_mismatch
{
  "error": "product mismatch: LO-260929-002 is not durian",
  "code": "product_mismatch"
}
Phản hồi 400 · application/json · invalid_idempotency_key
{
  "error": "invalid idempotency key: one header of 1 to 255 visible ASCII characters",
  "code": "invalid_idempotency_key"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 403 · application/json · csrf
{
  "error": "csrf token missing or invalid",
  "code": "csrf_token_missing_or_invalid"
}
Phản hồi 403 · application/json · origin
{
  "error": "origin not allowed",
  "code": "origin_not_allowed"
}
Phản hồi 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"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 409 · application/json · lot_is_open
{
  "error": "lot is open: a merge produces a new draft lot",
  "code": "lot_is_open"
}
Phản hồi 409 · application/json · lot_has_own_origin
{
  "error": "lot has own origin: LO-261002-031 names a growing area or harvest, and a merged lot takes its origin from its inputs",
  "code": "lot_has_own_origin"
}
Phản hồi 409 · application/json · lot_already_merged
{
  "error": "lot already merged: LO-260928-014",
  "code": "lot_already_merged"
}
Phản hồi 409 · application/json · lot_not_mergeable
{
  "error": "lot not mergeable: LO-260929-002 is open",
  "code": "lot_not_mergeable"
}
Phản hồi 409 · application/json · lot_on_hold
{
  "error": "lot on hold: LO-260929-002",
  "code": "lot_on_hold"
}
Phản hồi 409 · application/json · merge_chain_too_deep
{
  "error": "merge chain too deep: LO-260929-002 is 8 merges deep, at most 8",
  "code": "merge_chain_too_deep"
}
Phản hồi 409 · application/json · idempotency_key_in_use
{
  "error": "idempotency key in use: retry later",
  "code": "idempotency_key_in_use"
}
Phản hồi 409 · application/json · idempotency_key_used
{
  "error": "idempotency key used: the response is too large to replay",
  "code": "idempotency_key_used"
}
Phản hồi 409 · application/json · idempotency_key_unrecorded
{
  "error": "idempotency key used: the request ran but its response was not recorded",
  "code": "idempotency_key_used"
}
Phản hồi 413 · application/json
{
  "error": "body too large",
  "code": "body_too_large"
}
Phản hồi 422 · application/json
{
  "error": "idempotency key mismatch: the key was used with another request",
  "code": "idempotency_key_mismatch"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}

GET /v1/lots/{lot}/transformations

The lot merges a lot took part in

Xác thực: cookie, bearer, oauth2 · Phạm vi OAuth2: lot_read · getLotTransformations

#91: the merge that produced the lot and the merge that consumed it, each null when none did. Allowed for every role that reads lots (an operator only within its facilities). Not part of the partner SDK clients (x-not-in-sdk): SDK 0.2.0 was released before it.

Tham số

TênVị tríKiểuMô tả
lot
bắt buộc
pathstring

Lot code (unique within the tenant).

Phản hồi

Mã trạng tháiKiểuMô tả
200LotTransformations
application/json

The lot's merges.

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 lot for this tenant: a lot of another tenant, or of a facility outside an operator's facilities, 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.

Header của phản hồi

TênMã trạng tháiKiểuMô tả
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.

Ví dụ phản hồi

Phản hồi 200 · application/json
{
  "produced_by": {
    "event_id": "6f1c2a9e-3b7d-4c55-9a51-0d2e8f4b7c13",
    "lot": "LO-261002-031",
    "facility": "VN-TGPH-021",
    "inputs": [
      {
        "lot": "LO-260928-014",
        "quantity_kg": 349.6
      },
      {
        "lot": "LO-260929-002",
        "quantity_kg": 120.4
      }
    ],
    "input_kg": 470,
    "output_kg": 468.5,
    "mass_tolerance": 0.05,
    "recorded_at": 1790090000
  },
  "consumed_by": null
}
Phản hồi 400 · application/json
{
  "error": "bad request id",
  "code": "bad_request_id"
}
Phản hồi 401 · application/json
{
  "error": "missing or invalid token",
  "code": "missing_or_invalid_token"
}
Phản hồi 403 · application/json · role
{
  "error": "role not permitted",
  "code": "role_not_permitted"
}
Phản hồi 403 · application/json · tenant
{
  "error": "tenant not allowed",
  "code": "tenant_not_allowed"
}
Phản hồi 404 · application/json
{
  "error": "not found: LO-260928-014",
  "code": "not_found"
}
Phản hồi 405 · application/json
{
  "error": "method not allowed",
  "code": "method_not_allowed"
}
Phản hồi 500 · application/json
{
  "error": "internal error",
  "code": "internal_error"
}