# Publish Policy

`POST /policies/{bundleId}/publish` · Core · Policy & Approvals

Atomically publishes a draft bundle, activating it as the project's live policy. It validates the bundle, marks the previously published bundle as `superseded`, marks the draft `published`, and triggers Postgres RLS recompilation. Requires `PROJECT_ADMIN`.

Returns `K9O_POLICY_BUNDLE_INVALID` (422) if validation fails at publish time, leaving the previously published bundle active.

A rule's `requires_approval_from` is checked for shape only: a role nobody holds yet still publishes, and nobody can approve its cases until someone holds it.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `bundleId` | path | yes | The policy bundle id (`pol_...`). The `pol_` prefix may be left out. Example: `"pol_demo00000001"`. |
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `acknowledgeSelfLockout` | boolean | no | Set to true to publish a bundle that would take away your own read access to one or more collections. Without it such a publish is refused with 409 `K9O_POLICY_SELF_LOCKOUT_UNCONFIRMED`, naming the collections. The approver sees the acknowledged lockout on the pending change. |

## Responses

- **202**: Accepted

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | A publish waiting for approval. Nothing is in force yet. |
| `data.pendingChangeId` | string | yes | The id of the queued publish (`apr_...`). A different project admin approves or rejects it through the pending-approvals endpoints. |
| `data.bundleId` | string | yes | The bundle waiting to be published (`pol_...`). |
| `data.status` | enum ("pending_approval") | yes | Always `pending_approval`: the bundle is not published until an approver accepts the change. |
| `meta` | object | yes |  |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_SESSION_EXPIRED` | The caller's session token is expired or invalid; re-authenticate to continue. |
| 403 | `K9O_ACCESS_DENIED` | The caller does not hold PROJECT_ADMIN role, which is required to publish a policy bundle. |
| 404 | `K9O_POLICY_NOT_FOUND` | No policy bundle with the supplied identifier exists in this project. |
| 409 | `K9O_POLICY_PUBLISH_CONFLICT` | The bundle is already published or superseded and cannot be re-published. |
| 422 | `K9O_POLICY_BUNDLE_INVALID` | The bundle fails validation at publish time, for example because a referenced schema column was dropped since the draft was created. |
| 400 | `K9O_POLICY_NESTING_TOO_DEEP` | A policy rule in the bundle exceeds the maximum nesting depth of 20. |
| 400 | `K9O_POLICY_UNKNOWN_OPERATOR` | The bundle contains a policy rule with an unrecognised operator name. |
| 400 | `K9O_POLICY_UNKNOWN_CONTEXT_FIELD` | A subject or resource operand path in the bundle does not resolve to a known field. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/policies/<bundleId>/publish' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/policies/<bundleId>/publish', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({}),
});
const { data, meta } = await res.json();
```

### k9o CLI

```bash
k9o policy publish <id>
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.policies.publish('pol_demo00000001', {})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.policies.publish("pol_demo00000001", {})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Policies.Publish(ctx, "pol_demo00000001", map[string]any{})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.policies.publish("pol_demo00000001", json!({})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.policies().publish("pol_demo00000001", Map.of())
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Policies.PublishAsync("pol_demo00000001", new Dictionary<string, object> {  })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.policies.publish("pol_demo00000001", {  })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->policies->publish('pol_demo00000001', [])
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/publish-policy
