# Audit log

> A section of the Kumkuat API 1.0.0 reference. The rest of it: https://product.tech/docs-kumkuat-ai/api-reference.md (API Reference). Base URL: `https://api.kumkuat.ai`.

Security audit events for the workspace: sign-ins, member and role changes, API keys, settings changes, share links, exports and deletions. Poll the feed from a SIEM; needs the workspace.audit_log permission.

## List audit events (SIEM feed)

`GET /api/v1/audit-events`

Poll this from a SIEM. Events come oldest first; store `next_cursor` and pass it as `cursor` next time. Events appear about 5 seconds after they happen (the feed holds back the newest few seconds so a cursor never skips one). `order=desc` with `before` pages newest first instead. Needs the `workspace.audit_log` permission: owners and admins hold it, and a workspace API key created with `permissions: ["workspace.audit_log"]` can read the log and nothing else.

### Query parameters

- `cursor` (string): Return events after this cursor (from `next_cursor`).
- `since` (string): Only events at or after this time (ISO 8601). Use on the first poll instead of a cursor.
- `until` (string): Only events before this time (ISO 8601).
- `type` (string): Comma-separated event types, or a whole category such as `member.*`.
- `limit` (integer, default 100): Events per page, at most 1000.
- `order` (one of "asc", "desc", default "asc"): `asc` (feed order) or `desc` (newest first).
- `before` (string): With `order=desc`: events before this cursor.

### Returns (200, object)

OK

- `events` (array of object, required)
  - `actor` (object, required)
    - `api_key_id` (string, nullable): Id of the API key or session that made the request. Never the key itself.
    - `email` (string, nullable): The actor's email at the time of the event.
    - `type` (string, required): `user`, `service_key` (a workspace API key), `kumkuat_staff` (Kumkuat support acting in your workspace), `system` or `anonymous`.
    - `user_id` (string, nullable)
  - `cursor` (string, required): This event's position in the feed.
  - `detail` (object): Event-specific fields, e.g. a setting's old and new value. Credentials are masked to their last four characters.
  - `id` (string, required): Globally unique event id (`evt_...`). Use it to deduplicate.
  - `occurred_at` (string, required): UTC, ISO 8601.
  - `outcome` (string, required): `success` or `failure`.
  - `request_id` (string, nullable): Trace id of the request, for support.
  - `source` (object, required)
    - `ip` (string, nullable): Client IP address.
    - `user_agent` (string, nullable)
  - `target` (object, required)
    - `id` (string, nullable)
    - `name` (string, nullable)
    - `type` (string, nullable): What was acted on: `member`, `invitation`, `api_key`, `workspace`, `document`, `share_link`, ...
  - `type` (string, required, for example "member.role\_changed"): Event type; GET /api/v1/audit-events/types lists them.
  - `workspace_id` (string, nullable)
- `has_more` (boolean, required): True when another page is ready now; poll again immediately.
- `next_cursor` (string, nullable): Pass as `cursor` on the next call. Null only when the call had no cursor and nothing matched.
- `order` (string, required)

### Responses

- `200`: OK
- `422`: Unprocessable Entity

### Example request

```bash
curl https://api.kumkuat.ai/api/v1/audit-events \
  -H 'X-API-Key: <api key>'
```

### Example response

```json
{
  "events": [
    {
      "actor": {},
      "cursor": "string",
      "detail": {},
      "id": "string",
      "occurred_at": "string",
      "outcome": "string"
    }
  ],
  "has_more": true,
  "next_cursor": "string",
  "order": "string"
}
```

## Download audit events as CSV

`GET /api/v1/audit-events/export.csv`

Every event from `since` (default: 30 days ago) to `until` (default: now) as CSV, oldest first. Takes the same `type` filter as the feed. Columns: occurred_at, type, outcome, actor_type, actor_email, actor_user_id, api_key_id, source_ip, user_agent, target_type, target_id, target_name, detail (JSON), id, request_id. Each download is recorded as an `audit_log.exported` event.

### Responses

- `422`: Unprocessable Entity

### Example request

```bash
curl https://api.kumkuat.ai/api/v1/audit-events/export.csv \
  -H 'X-API-Key: <api key>'
```

## List audit event types

`GET /api/v1/audit-events/types`

Every event type the audit log records, with what it means.

### Returns (200, object)

OK

- `retention_days` (integer, required): How long events are kept.
- `types` (array of object, required)
  - `category` (string, required)
  - `description` (string, required)
  - `type` (string, required)

### Responses

- `200`: OK
- `422`: Unprocessable Entity

### Example request

```bash
curl https://api.kumkuat.ai/api/v1/audit-events/types \
  -H 'X-API-Key: <api key>'
```

### Example response

```json
{
  "retention_days": 0,
  "types": [
    {
      "category": "string",
      "description": "string",
      "type": "string"
    }
  ]
}
```
