audit
2 个操作
GET /v1/auditAudit log of the caller's tenantGET /v1/audit.csvActivity log of the caller's tenant (CSV)
GET /v1/audit
Audit log of the caller's tenant
身份验证:cookie, bearer, oauth2 · OAuth2 作用域:tenant_read · listAudit
Append-only audit rows of the caller's tenant, newest first, with keyset pagination: the company's activity log (SELF-1-7, #188). Every request that reaches the handler of a mutating route writes exactly one row (ingest and broker authorization are exempt). Rows cannot be changed or deleted: there is no route for it and the table refuses it. A successful sign-in is filed under the company the session first acts for (the user's first membership); a failed sign-in carries no company and appears in no company's log. Each item names who the actor is (actor_kind, actor_name); CropPath staff (platform admins) acting for the company are support. Filters combine (every one given must match). Allowed for auditor, tenant_admin and platform_admin.
参数
| 名称 | 位置 | 类型 | 说明 |
|---|---|---|---|
entity可选 | query | string | Only rows about this entity type. |
actor可选 | query | string | Only rows by this actor. |
entity_id可选 | query | string | Only rows about this record id (for example a lot code). An id longer than 128 characters is matched as its stored SHA-256 form. At most 512 characters. |
action_prefix可选 | query | string | Only rows whose action starts with one of these comma-separated prefixes (at most 30; lowercase dotted words, for example |
since可选 | query | string | Only rows at or after this time: an ISO 8601 date or date-time (+07:00 when it has no offset). |
until可选 | query | string | Only rows before this time (exclusive), as |
cursor可选 | query | string |
|
limit可选 | query | integer | Page size, 1 to 200. |
响应
| 状态码 | 类型 | 说明 |
|---|---|---|
| 200 | AuditPageapplication/json | One page of audit rows. |
| 400 | Errorapplication/json | A cursor that is not one this API issued, a limit outside 1 to 200, a malformed filter (action prefix, since, until, a range whose until is not after since, a record id over 512 characters), or a bad X-Request-Id. |
| 401 | Errorapplication/json | No valid session, API token or legacy token. |
| 403 | Errorapplication/json | The caller is known but refused: role not permitted (operator and lab) or tenant not allowed (X-Tenant). |
| 405 | Errorapplication/json | The path exists but not for this method. |
| 500 | Errorapplication/json | Unexpected failure; the detail is only in the server log. |
响应头
| 名称 | 状态码 | 类型 | 说明 |
|---|---|---|---|
X-Request-Id | 200 | string | Request id: the caller's |
X-Request-Id | 400 | string | Request id: the caller's |
X-Request-Id | 401 | string | Request id: the caller's |
X-Request-Id | 403 | string | Request id: the caller's |
X-Request-Id | 405 | string | Request id: the caller's |
Allow | 405 | string | Comma-separated methods the path accepts. |
X-Request-Id | 500 | string | Request id: the caller's |
响应示例
响应 200 · application/json
{
"items": [
{
"id": 42,
"at": 1790000000.5,
"actor": "admin@coop.example",
"tenant": "coop-dl",
"action": "envelope.review",
"entity": "envelope",
"entity_id": "3f2b8f0e-6a39-4f7e-9b1e-0d6c1c5e7a11",
"before_hash": "9b0f1d6a2c7e4b3f8a5d0c9e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c",
"after": {
"status": 200,
"id": "3f2b8f0e-6a39-4f7e-9b1e-0d6c1c5e7a11",
"decision": "approve",
"result": "accepted"
},
"request_id": "req-7f3a",
"ip_hash": "c3a1e07d94b2f58a61d0e7c4b9f3a2d8e5c17b60f4a9d2e3b8c5f1a7d0e4b962",
"actor_kind": "member",
"actor_name": "Nguyễn Văn An"
}
],
"next_cursor": "eyJpZCI6NDJ9"
}响应 400 · application/json · bad_cursor
{
"error": "bad cursor",
"code": "bad_cursor"
}响应 400 · application/json · bad_limit
{
"error": "bad limit",
"code": "bad_limit"
}响应 400 · application/json · bad_request_id
{
"error": "bad request id",
"code": "bad_request_id"
}响应 400 · application/json · bad_action_prefix
{
"error": "bad action prefix",
"code": "bad_action_prefix"
}响应 400 · application/json · bad_since
{
"error": "bad since",
"code": "bad_since"
}响应 400 · application/json · bad_until
{
"error": "bad until",
"code": "bad_until"
}响应 400 · application/json · bad_range
{
"error": "bad range",
"code": "bad_range"
}响应 400 · application/json · bad_entity_id
{
"error": "bad entity id",
"code": "bad_entity_id"
}响应 401 · application/json
{
"error": "missing or invalid token",
"code": "missing_or_invalid_token"
}响应 403 · application/json · role
{
"error": "role not permitted",
"code": "role_not_permitted"
}响应 403 · application/json · tenant
{
"error": "tenant not allowed",
"code": "tenant_not_allowed"
}响应 405 · application/json
{
"error": "method not allowed",
"code": "method_not_allowed"
}响应 500 · application/json
{
"error": "internal error",
"code": "internal_error"
}GET /v1/audit.csv
Activity log of the caller's tenant (CSV)
身份验证:cookie, bearer, oauth2 · OAuth2 作用域:tenant_read · getAuditCsv
The rows GET /v1/audit lists for the same filters, newest first, as a CSV download (SELF-1-7, #188): at most 10,000 rows per file; when more match, X-Next-Cursor is the cursor of the next file. An audited read (export.audit: which filters were set, by name, the parsed range and action prefixes, and the row count), downloaded as an attachment, never cached. Allowed for auditor, tenant_admin and platform_admin acting for the tenant; another tenant's rows never appear.
参数
| 名称 | 位置 | 类型 | 说明 |
|---|---|---|---|
entity可选 | query | string | Only rows about this entity type. |
actor可选 | query | string | Only rows by this actor. |
entity_id可选 | query | string | Only rows about this record id (for example a lot code). An id longer than 128 characters is matched as its stored SHA-256 form. At most 512 characters. |
action_prefix可选 | query | string | Only rows whose action starts with one of these comma-separated prefixes (at most 30; lowercase dotted words, for example |
since可选 | query | string | Only rows at or after this time: an ISO 8601 date or date-time (+07:00 when it has no offset). |
until可选 | query | string | Only rows before this time (exclusive), as |
cursor可选 | query | string | The previous file's |
响应
| 状态码 | 类型 | 说明 |
|---|---|---|
| 200 | stringtext/csv | CSV with a header row (id, time_utc, actor, actor_kind, actor_name, action, entity, entity_id, status, error, request_id; CRLF line ends), then one row per audit row. time_utc is ISO 8601 UTC. A text cell starting with =, +, -, @, a tab or a carriage return gets a leading ' so a spreadsheet never runs it as a formula. |
| 400 | Errorapplication/json | A cursor that is not one this API issued, a malformed filter (action prefix, since, until, a range whose until is not after since, a record id over 512 characters), or a bad X-Request-Id. |
| 401 | Errorapplication/json | No valid session, API token or legacy token. |
| 403 | Errorapplication/json | The caller is known but refused: role not permitted (operator and lab) or tenant not allowed (X-Tenant). |
| 405 | Errorapplication/json | The path exists but not for this method. |
| 500 | Errorapplication/json | Unexpected failure; the detail is only in the server log. |
响应头
| 名称 | 状态码 | 类型 | 说明 |
|---|---|---|---|
X-Request-Id | 200 | string | Request id: the caller's |
X-Next-Cursor | 200 | string | The cursor of the next file; absent on the last. |
X-Request-Id | 400 | string | Request id: the caller's |
X-Request-Id | 401 | string | Request id: the caller's |
X-Request-Id | 403 | string | Request id: the caller's |
X-Request-Id | 405 | string | Request id: the caller's |
Allow | 405 | string | Comma-separated methods the path accepts. |
X-Request-Id | 500 | string | Request id: the caller's |
响应示例
响应 200 · text/csv
id,time_utc,actor,actor_kind,actor_name,action,entity,entity_id,status,error,request_id
42,2026-10-10T01:30:00Z,admin@coop.example,member,Nguyễn Văn An,lot.seal,lot,LO-260928-014,200,,req-7f3a
响应 400 · application/json · bad_cursor
{
"error": "bad cursor",
"code": "bad_cursor"
}响应 400 · application/json · bad_request_id
{
"error": "bad request id",
"code": "bad_request_id"
}响应 400 · application/json · bad_action_prefix
{
"error": "bad action prefix",
"code": "bad_action_prefix"
}响应 400 · application/json · bad_since
{
"error": "bad since",
"code": "bad_since"
}响应 400 · application/json · bad_until
{
"error": "bad until",
"code": "bad_until"
}响应 400 · application/json · bad_range
{
"error": "bad range",
"code": "bad_range"
}响应 400 · application/json · bad_entity_id
{
"error": "bad entity id",
"code": "bad_entity_id"
}响应 401 · application/json
{
"error": "missing or invalid token",
"code": "missing_or_invalid_token"
}响应 403 · application/json · role
{
"error": "role not permitted",
"code": "role_not_permitted"
}响应 403 · application/json · tenant
{
"error": "tenant not allowed",
"code": "tenant_not_allowed"
}响应 405 · application/json
{
"error": "method not allowed",
"code": "method_not_allowed"
}响应 500 · application/json
{
"error": "internal error",
"code": "internal_error"
}