/approval-policiesCreate Approval Policy
Creates a new draft policy bundle for the project, assigned a stable bundleId (bnd_<base62>).
The bundle is initialized in draft status with no runtime effect.
It can be edited via PATCH and then atomically activated via the publish endpoint.
These validation checks fire at draft creation time:
K9O_POLICY_NESTING_TOO_DEEP(400) if nesting depth exceeds 20.K9O_POLICY_UNKNOWN_OPERATOR(400) for unknown operators.K9O_POLICY_UNKNOWN_CONTEXT_FIELD(400) for unknown context fields.
K9O_POLICY_BUNDLE_INVALID (422) is returned when a bundle passes creation-time validation but later fails at publish time (e.g., schema drifted between draft and publish).
Requires PROJECT_ADMIN.
| projectSlug * | path | The project's slug: the path segment after It is unique within the org. |
| collection * | string | The collection whose writes the policy applies to: a letter or underscore, then up to 62 letters, digits or underscores. |
| operation * | "insert" | "update" | "delete" | The kind of write the policy applies to. |
| predicate * | object | The condition, as a JSON predicate: Operators: A string that starts with
Any other value is a literal. A predicate with an operator or shape the platform can't evaluate is refused with 400 |
| action * | "auto_approve" | "queue" |
In a strict-governance project, creating an |
| HTTP | K9O Code | Description |
|---|---|---|
| 201 | Created | |
| 400 | K9O_POLICY_NESTING_TOO_DEEP | The approval policy rule exceeds the maximum nesting depth of 20. |
| 400 | K9O_POLICY_UNKNOWN_OPERATOR | The approval policy contains a rule with an operator name not in the supported vocabulary. |
| 400 | K9O_POLICY_UNKNOWN_CONTEXT_FIELD | A subject or resource operand path in the approval policy does not resolve to a known field. |
| 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 or PROJECT_AUTHOR role, which is required to author an approval policy. |
| 403 | K9O_POLICY_AUTHORING_AUTHORITY_INSUFFICIENT | The caller's role is not authorised under the org-policy constraint to author an approval rule for the targeted collection and operation scope. |
| 422 | K9O_POLICY_BUNDLE_INVALID | The approval policy declaration is structurally well-formed but fails domain-level validation at apply time. |
| data * | object | An approval policy: which writes to a collection it matches, and whether a match is applied or held for a checker. |
| id * | string | The policy id ( |
| collection * | string | The collection whose writes the policy applies to. |
| operation * | "insert" | "update" | "delete" | The kind of write the policy applies to. |
| predicate * | object | The condition, as a JSON predicate: Operators: A string that starts with
Any other value is a literal. |
| action * | "auto_approve" | "queue" | What happens to a matching write: Policies for the same collection and operation are tried oldest first, and the first whose predicate matches decides. |
| authoredBy * | string | The id of the user who created the policy ( |
| createdAt * | string <date-time> | When the policy was created. |
| meta * | any |
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.approvalPolicies.create({})Showing example in TypeScript
{
"collection": "string",
"operation": "insert",
"action": "auto_approve"
}{
"data": {
"id": "string",
"collection": "string",
"operation": "insert",
"action": "auto_approve",
"authoredBy": "string",
"createdAt": "string"
}
}