Browse documentation

admin-data API

POST|GET|PATCH|DELETE /api/admin-data is the single generic CRUD endpoint custom apps use for all runtime records. It resolves types, evaluates the record's stamped design_schema permissions, stamps schemas on write, soft-deletes, and fires triggers. Custom apps must route record CRUD through it rather than shipping their own record functions — the shared permission, type-resolution, audit, and trigger logic lives here.

Handler: .framework/functions/admin-data.ts via createHandler, so every request is authenticated and wrapped in the standard envelope — see Authentication and Errors and Envelopes.

Request model

Action and entity come from the query string; record fields come from the JSON body (writes) or additional query params (reads). With no action, the HTTP method picks the verb (GET+id → get, GET → list, POST → create, PATCH → update, DELETE → remove).

ActionMethodParams
listGETentity (required), search, type_slug, type_slugs (csv), sort_field (default created_at), sort_direction (asc/desc, default desc), limit (default 50), offset, view, flag_only, exclude_flag, plus any other key=value as eq filters (is_active/is_verified/is_primary coerce 'true' → boolean)
getGETentity, id, view, lineage=0 (items only — skips lineage attach)
statsGETentity → {entity, count}
createPOSTentity (query or body), type_slug or type_id (required for non-raw entities), record fields
updatePATCHentity, id, record fields (partial)
removeDELETEentity, id, soft (default 'true')

Valid entities: accounts, people, items, threads, messages, links, attachments, watchers, item_progress, logs, test_runs, observability, test_cases, types, link_types, ai_agents, prompt_configs.

logs, test_runs, observability, test_cases are raw entities: create takes a per-entity field allowlist, requires specific fields (logs: level+message; test_runs: suite; observability: metric_name+metric_value; test_cases: slug+name), and needs no type_id.

Response shapes

All responses use the standard envelope {data, error, meta:{requestId, duration}}. data is:

  • list → array of sanitized records, or {data, schema, view} when view+type_slug are passed and the type's design_schema resolves
  • get → the sanitized record (+parents/children/type_slug lineage on items unless lineage=0), or {data, schema, view} when view is passed and the record carries design_schema
  • create/update → the sanitized record
  • remove → {deleted: true, soft: true, data: <record>} on soft delete; {deleted: true, soft: false} on hard delete
  • stats → {entity, count}

Sanitization applies design_schema.fields.*.permissions: fields the principal cannot read are stripped before the row is returned.

Permission evaluation order

  1. createHandler resolves the principal (401 if anonymous).
  2. create → resolveFirstSurfacePermissions(personId, accountId, typeSlug, 'create', designSchema); machine principals with *:* scope bypass. Denied → 403.
  3. update → validateFirstSurfaceUpdatePermissions on the existing record's stamped design_schema (no record_permissions → deny); each data.<field> written requires field write; sanitizes values through validation_schema. system_admin bypasses.
  4. remove → resolveFirstSurfacePermissions(..., 'delete', existing.design_schema); system_admin bypasses.
  5. list/get run under ctx.db (RLS-scoped for humans, adminDb for internal/system-admin), then per-record sanitization. An explicit account_id IN <accessible> filter is applied on top — it is the sole tenancy guard for machines on adminDb — and for items it mirrors the items_access platform branch so scope: 'platform' rows on spine-system stay readable by every actor (reads only; writes stay account-confined).

Stamping & account resolution on create

  • type_slug resolves via resolveTypeRecord(kind, slug) (kind from ENTITY_TO_KIND); type_id fetches the row and requires is_active. One of the two is mandatory — "every runtime record must reference a type".
  • The record is stamped with the type's design_schema and validation_schema at insert; a missing record_permissions merges {all: [create,read,update,delete]}.
  • account_id in the body is a request hint, not a field — it sets the target account when permitted; otherwise ctx.accountId.
  • scope: 'platform' types are stamped with the spine-system account; children created via thread_id/target_id/parent_id inherit the parent's account and scope (missing parent → 403).
  • created_by/updated_by stamp people.id for human principals; types/link_types have no audit columns and skip the stamp.
  • checkTypeSlugRateLimit enforces per-type create policies from apps.config.rate_limits['<type_slug>_create'].

Soft delete

remove with soft=true (default) sets is_active=false + updated_by/ updated_at on accounts, people, items, threads, messages, watchers, item_progress, test_cases. Any other entity — or soft=false — performs a hard DELETE.

Visibility projection

Principals without internal-audience roles never see visibility: 'internal' threads (filtered or 404), and internal messages are projected to safe step summaries via projectMessageForCustomer — unless the parent thread is external/public.

Triggers

create/update await fireCreateTriggers / fireUpdateTriggers (errors logged, never fail the request). remove fires nothing — fireDeleteTriggers is imported but never called, so *_deleted triggers do not run on this path. Update triggers receive the previous row for field-change evaluation.

Examples

# List open items of a type
GET /api/admin-data?action=list&entity=items&type_slug=ticket&status=open&limit=25

# Get one item without lineage
GET /api/admin-data?action=get&entity=items&id=<uuid>&lineage=0

# Create a ticket (type by slug)
POST /api/admin-data?action=create
{"entity": "items", "type_slug": "ticket", "title": "Login broken",
 "data": {"priority": "high"}}

# Partial update — only listed data fields are written, each needs field 'write'
PATCH /api/admin-data?action=update&entity=items&id=<uuid>
{"data": {"priority": "low"}, "status": "resolved"}

# Soft then hard delete
DELETE /api/admin-data?action=remove&entity=items&id=<uuid>
DELETE /api/admin-data?action=remove&entity=items&id=<uuid>&soft=false

Client-side, .framework/src/hooks/useEntityRecord.ts shows the canonical call pattern through apiFetch (.framework/src/lib/api.ts), which attaches Authorization, X-Account-Id, traceparent, and x-app-id.

Common failures

StatusCause
400missing/invalid entity, missing id, missing type_id/type_slug on create, missing required raw-entity fields
401no valid credential — see Authentication
403record/field permission denied; parent record not found or not accessible
404-styleget/update/remove on an inaccessible row errors "Record not found or access denied" (RLS hides it)

Framework documentation — Verified November 20, 2026 · source revision 666f107.

Was this page helpful? Ask a question · Report a documentation problem