Collections
Collection methods map to /api/collections routes. collections.list and collections.get need the read ability; create, update, delete, and reorder need admin (see Authentication).
Access them from the client returned by createClient:
const noma = createClient({ projectId, apiKey })collections.list
Returns all collections in the project, including field definitions. See List Collections for the HTTP contract.
const collections = await noma.collections.list()collections.get
Fetch one collection by slug, including its fields when the API includes them.
const collection = await noma.collections.get("blog-posts")| Argument | Type | Description |
|---|---|---|
collectionSlug | string | Collection slug (for example blog-posts). |
collections.create
Create a collection. The payload matches the API body (name, slug, optional is_singleton, optional inline fields, and so on).
await noma.collections.create({
name: "Blog posts",
slug: "blog-posts",
is_singleton: false,
fields: [
{
type: "text",
label: "Title",
name: "title",
options: {
repeatable: false,
hideInContentList: false,
hiddenInAPI: false,
},
validations: {
required: { status: true, message: "Title is required" },
},
},
],
})The API expects is_singleton (boolean). Inline fields entries need type, label, and name like standalone field creation. Use validations for required/unique rules. Pass a Record<string, unknown>; see Fields and Create a Collection.
collections.update
Replace collection metadata for a given slug. PUT requires both name and slug on every update (even if the slug stays the same).
await noma.collections.update("blog-posts", {
name: "Articles",
slug: "blog-posts",
})| Argument | Type | Description |
|---|---|---|
collectionSlug | string | Target collection slug (URL path). |
payload | Record<string, unknown> | Request body. Must include name and slug per API validation. |
collections.delete
Delete a collection by slug. The SDK sends {"slug": "<slug>"} in the JSON body, as required by the API.
await noma.collections.delete("old-posts")Deleting a collection removes its fields and entries. Confirm backups or exports first.
collections.reorder
Change display order for collections in the dashboard.
import type { CollectionsReorderPayload } from "@nomacms/js-sdk"
const payload: CollectionsReorderPayload = {
collections: [
{ uuid: "uuid-1", order: 0 },
{ uuid: "uuid-2", order: 1 },
],
}
await noma.collections.reorder(payload)| Field | Description |
|---|---|
collections | Array of { uuid, order } entries. |
Related
- List Collections -
GET /api/collections - Get a Collection -
GET /api/collections/{slug} - Create a Collection -
POST /api/collections - Update a Collection -
PUT /api/collections/{slug} - Delete a Collection -
DELETE /api/collections/{slug} - Reorder Collections -
POST /api/collections/reorder - Fields - Add or update fields on a collection.
- Content - Create and list entries inside a collection.