Skip to content

Documentation

Collections (collections.ts)

Reference for managing content collections — CRUD operations, schema discovery, and entry revisions.

4/12/2026
2 min read Edit on GitHub

The Collections API provides standard CRUD (Create, Read, Update, Delete) operations for managing content entries. It handles schema discovery, data validation, and multi-tenant isolation through a database-agnostic interface.


⚡ Quick Reference

Feature HTTP Endpoint Method Permission Required
List Schemas /api/collections GET collections:read
Find Entries /api/collections/{id} GET collections:read
Get Entry /api/collections/{colId}/{entId} GET collections:read
Create Entry /api/collections/{id} POST collections:create
Update Entry /api/collections/{colId}/{entId} PATCH collections:update
Delete Entry /api/collections/{colId}/{entId} DELETE collections:delete

1. Schema Discovery

Use the root collections endpoint to discover the structure and metadata of your content models.

Endpoint: GET /api/collections
Query Parameters:

  • includeFields: If true, returns the full widget configuration for each collection.
  • includeStats: If true, returns count and health metrics for each collection.

2. Entry Management

Retrieval & Searching

To fetch entries from a specific collection, use the ID-based endpoint.

Endpoint: GET /api/collections/{collectionId}
Advanced Filtering: See the Content & Search Reference for deep query syntax.

Modifying Content

SveltyCMS enforces schema validation (via Valibot) on every write operation.

  • Create: POST /api/collections/{collectionId}
  • Update: PATCH /api/collections/{collectionId}/{entryId}

Soft Deletion: By default, the DELETE method moves entries to the Trash. Permanent deletion requires the ?permanent=true query parameter.


3. The Mechanics

Architecture

The Collections handler acts as a thin dispatcher that invokes the LocalCMS SDK, which in turn coordinates between the Database Adapter and the Widget System.

sequenceDiagram participant Client participant API as Collections Handler participant SDK as LocalCMS SDK participant DB as Database Adapter Client->>API: POST /api/collections/posts API->>SDK: cms.collections.create('posts', data) SDK->>DB: INSERT INTO collection_posts ... DB-->>Client: 201 Created (JSON Entry)

Related Documents

apicollectionscontentcrud
Was this page helpful?