/policiesCreate Policy Draft
Creates a new draft policy bundle for the project.
The bundle is immediately editable and has no runtime effect until published.
Requires PROJECT_ADMIN.
The response includes the assigned bundleId (bnd_<base62>) which is the stable handle for all subsequent lifecycle operations on the bundle.
| projectSlug * | path | The project's slug: the path segment after It is unique within the org. |
| policy * | object | The policy document. Every block is optional. A key other than these seven is refused with 422 |
| collections | any | Row-level rules per collection, keyed by collection name. Each collection holds An action with no rule is denied. Publishing compiles these rules into the database's row-level security. |
| One of: object | ||
| or: null | ||
| storage | any | Storage rules per bucket, keyed by bucket name. They are checked on each storage request. |
| One of: object | ||
| or: null | ||
| tools | any | Rules for tool calls, keyed by the tool's platform name or Each tool takes Each verb takes a rule list: a rule name from |
| One of: object | ||
| or: null | ||
| functions | any | Rules for functions, keyed by function name, Each function takes Each verb takes a rule list: a rule name from Only |
| One of: object | ||
| or: null | ||
| secrets | any | Rules for secrets: Each verb takes a rule list: a rule name from |
| One of: object | ||
| or: null | ||
| streams | any | Rules for streams, keyed by stream name or Each stream takes Each verb takes a rule list: a rule name from |
| One of: object | ||
| or: null | ||
| analytics | any | Rules for analytics datasets, keyed by dataset slug or Each dataset takes Each verb takes a rule list: a rule name from |
| One of: object | ||
| or: null | ||
| rules | any | The named-rule catalogue, an array of rule objects that the unit surfaces refer to by name. Each rule has a With
Omit it or send null for no catalogue. |
| editorMode | "visual" | "json" | "unspecified" | The editor the bundle was written in, so a console can reopen it in the same one: |
| HTTP | K9O Code | Description |
|---|---|---|
| 201 | Created | |
| 400 | K9O_POLICY_NESTING_TOO_DEEP | The policy rule in the submitted bundle exceeds the maximum nesting depth of 20; simplify the rule structure. |
| 400 | K9O_POLICY_UNKNOWN_OPERATOR | The submitted bundle contains a policy rule with an operator name not in the supported vocabulary. |
| 400 | K9O_POLICY_UNKNOWN_CONTEXT_FIELD | A subject or resource operand path in the submitted bundle does not match any known field for the target collection. |
| 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 create a policy bundle draft. |
| 403 | K9O_POLICY_AUTHORING_AUTHORITY_INSUFFICIENT | The caller's role is not authorised to author the approval rules declared in the submitted bundle for the targeted collection and operation scope. |
| data * | object | A policy bundle: the policy document, its named rules and where it is in its lifecycle. |
| id * | string | The bundle id ( |
| projectId * | string | The project the bundle belongs to ( |
| status * | "draft" | "published" | "superseded" |
|
| policy * | object | The policy document as stored: |
| rules | object[] | The named-rule catalogue. Present only when the bundle has one. |
| createdBy * | string | The id of the user who created the bundle ( |
| createdAt * | string <date-time> | When the bundle was created. |
| publishedAt * | any | When the bundle was published. Null for a draft. |
| One of: string <date-time> | ||
| or: null | ||
| supersededAt * | any | When the bundle stopped being in force. Null unless |
| One of: string <date-time> | ||
| or: null | ||
| supersededBy * | any | The id of the bundle that replaced this one. Null when nothing replaced it. |
| One of: string | ||
| or: null | ||
| source * | "rest" | "migration" | "cli" | How the bundle was created: |
| editorMode * | "visual" | "json" | "unspecified" | The editor the bundle was written in, so a console can reopen it in the same one: |
| supersededReason * | any | The reason given when the bundle was deactivated. Null otherwise. |
| One of: string | ||
| or: null | ||
| pendingChangeId * | any | The id of a queued publish for this bundle that is waiting for an approver ( Set on the list and single-bundle reads; null when nothing is queued, and always null in create, update and current-policy responses. |
| One of: string | ||
| or: null | ||
| meta * | any | |
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.policies.create({
policy: {
collections: {},
storage: {}
},
editorMode: 'visual'
})Showing example in TypeScript
{
"policy": {
"collections": {},
"storage": {}
},
"editorMode": "visual"
}{
"data": {
"id": "string",
"projectId": "string",
"status": "draft",
"rules": [],
"createdBy": "string",
"createdAt": "string",
"publishedAt": "string",
"supersededAt": "string",
"supersededBy": "string",
"source": "rest",
"editorMode": "visual",
"supersededReason": "string",
"pendingChangeId": "string"
}
}