# Workloads API

## GET /api/v1/admin/workloads

`GET /api/v1/admin/workloads` · operation `listWorkloads`

Global admin or viewer lists team workloads (non-human key owners) with responsible user state and active owned managed key count. Requires identity_ownership and identity_management. Scope and filters apply before count and page in one snapshot.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `team` | query | string, max length 64 | Only this team's workloads. |
| `status` | query | string, one of `"active"`, `"disabled"`, `"all"`, default `"active"` | active (default), disabled or all. |
| `search` | query | string, max length 128 | Literal name search or exact ID |
| `limit` | query | integer, default `50`, min 1, max 100 | Most rows on this page, 1-100 (50 by default). |
| `offset` | query | integer, default `0`, min 0, max 10000 | Rows to skip before this page, for pagination (0-10000). |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Workload page | `application/json`: object |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Feature disabled | `application/json`: [Error](/docs/api/schemas/e/#error) |

Response `200` fields:

- `application/json`: object
  - `items` (array of [Workload](/docs/api/schemas/w/#workload), required)
  - `total` (integer (int64), required)
  - `limit` (integer, required)
  - `offset` (integer, required)


## POST /api/v1/admin/workloads

`POST /api/v1/admin/workloads` · operation `createWorkload`

Global admin creates a console workload in an active team with a server-generated wl_ ID. A workload never receives a session, role or credential; it only owns keys for attribution.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `team` (string, required) — Existing active team ID; immutable after creation
  - `name` (string, required, min length 2, max length 128)
  - `description` (string, max length 512)
  - `responsible` (string, pattern `^usr_[a-f0-9]{32}$`) — Optional active console user accountable for the workload
  - `disabled` (boolean) — Disabled workloads keep existing keys working but accept no new bindings

**Responses**

| Status | Description | Body |
|---|---|---|
| `201` | Created workload | `application/json`: [Workload](/docs/api/schemas/w/#workload) |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Team not found or feature disabled | — |
| `409` | Generated workload ID collision; retry | — |


## GET /api/v1/admin/workloads/{id}

`GET /api/v1/admin/workloads/{id}` · operation `getWorkload`

Workload metadata plus up to 100 most recent managed keys it owns (including revoked) and declared YAML keys that reference it.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required |  |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | workload, managed_keys, declared_keys and keys_note | — |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Workload not found or feature disabled | — |


## PUT /api/v1/admin/workloads/{id}

`PUT /api/v1/admin/workloads/{id}` · operation `updateWorkload`

Global admin edits name, description, responsible user and disabled state of a console workload with its current version. The team cannot change. YAML workloads are operator-owned.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Request body** (required)

- `application/json`: object
  - `name` (string, required, min length 2, max length 128)
  - `description` (string, max length 512)
  - `responsible` (string, pattern `^usr_[a-f0-9]{32}$`)
  - `disabled` (boolean)
  - `version` (integer (int64), required, min 0)

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | Updated workload | `application/json`: [Workload](/docs/api/schemas/w/#workload) |
| `400` | Invalid input | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Workload not found or feature disabled | — |
| `409` | Stale version or YAML-owned workload | — |


## DELETE /api/v1/admin/workloads/{id}

`DELETE /api/v1/admin/workloads/{id}` · operation `deleteWorkload`

Soft-delete a console workload that owns no active managed key. Historical events keep the captured owner ID.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Responses**

| Status | Description | Body |
|---|---|---|
| `204` | Workload deleted | — |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Workload not found or feature disabled | — |
| `409` | Workload owns active managed keys or is YAML-owned | — |


## POST /api/v1/admin/workloads/{id}/revoke-keys

`POST /api/v1/admin/workloads/{id}/revoke-keys` · operation `revokeWorkloadKeys`

Kill switch. Revokes every active managed key owned by the workload in one transaction and audits each key. Declarative YAML keys are listed in declared_key_ids and stay active until removed from configuration.

**Authentication:** `adminSession`

**Parameters**

| Name | In | Type | Description |
|---|---|---|---|
| `id` | path | string, required |  |
| `X-CSRF-Token` | header | string, required | Token returned by admin login/session; required with the same-origin session cookie for writes. |

**Responses**

| Status | Description | Body |
|---|---|---|
| `200` | revoked_key_ids, declared_key_ids and note | — |
| `403` | Model not allowed | `application/json`: [Error](/docs/api/schemas/e/#error) |
| `404` | Workload not found or feature disabled | — |

