Noma

Create a Collection

Create a Collection

Creates a new collection. You can optionally pass an inline fields array to define fields in the same request (including group fields with children).

Request

POST /api/collections HTTP/1.1
Host: app.nomacms.com
Content-Type: application/json
project-id: <project-uuid>
Authorization: Bearer <api-token>
Accept: application/json

Requires the admin ability on the token.

JSON body

FieldTypeRequiredDescription
namestringYesDisplay name (max 60 characters)
slugstringYesUnique per project; lowercase kebab-case (max 60). Cannot be collections, files, or webhooks.
is_singletonbooleanNoDefaults to false. If true, the collection allows at most one content entry.
fieldsarrayNoTop-level field definitions (see below)

fields items (when present)

Each item:

FieldTypeRequiredDescription
typestringYesField type (for example text, group, relation)
labelstringYesEditor label (max 60 characters)
namestringYesAPI key; lowercase letters, digits, and single hyphens between segments
descriptionstringNoHelp text
placeholderstringNoPlaceholder
optionsobjectNoType-specific options (for relation fields, options.relation.collection may be a collection slug string; the API resolves it to an id)
validationsobjectNoValidation rules
childrenarrayNoOnly for type: "group": nested field objects with the same columns as above (no nested children in API tests)

Field name must match: ^[a-z0-9]+(?:-[a-z0-9]+)*$.

Response (201)

JSON object: created collection with fields loaded (array, possibly empty). Shape matches Get a Collection (uuid, name, slug, is_singleton, created_at, updated_at, fields).

Errors

StatusWhen
400Missing project-id or project cannot be resolved
401Missing or invalid bearer token
403Token does not have admin (or *)
404No project with that UUID
422Validation failed (duplicate slug, reserved slug, invalid field names, relation target missing, and so on)
429Rate limited

Example

import { createClient } from "@nomacms/js-sdk"
 
const client = createClient({
  projectId: process.env.NOMA_PROJECT_ID!,
  apiKey: process.env.NOMA_API_KEY!,
})
 
const created = await client.collections.create({
  name: "Products",
  slug: "products",
  is_singleton: false,
  fields: [
    {
      type: "text",
      label: "Title",
      name: "title",
      validations: {
        required: { status: true, message: "Title is required" },
      },
    },
  ],
})
 
console.log(created)
import axios from "axios"
 
async function main() {
  const { data } = await axios.post(
    "https://app.nomacms.com/api/collections",
    {
      name: "Products",
      slug: "products",
      is_singleton: false,
      fields: [
        {
          type: "text",
          label: "Title",
          name: "title",
          validations: {
            required: { status: true, message: "Title is required" },
          },
        },
      ],
    },
    {
      headers: {
        "Content-Type": "application/json",
        "project-id": process.env.NOMA_PROJECT_ID!,
        Authorization: `Bearer ${process.env.NOMA_API_KEY}`,
        Accept: "application/json",
      },
    },
  )
  console.log(data)
}
 
void main()
<?php
 
$payload = json_encode([
    'name' => 'Products',
    'slug' => 'products',
    'is_singleton' => false,
    'fields' => [
        [
            'type' => 'text',
            'label' => 'Title',
            'name' => 'title',
            'validations' => [
                'required' => ['status' => true, 'message' => 'Title is required'],
            ],
        ],
    ],
]);
 
$ch = curl_init('https://app.nomacms.com/api/collections');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Content-Length: ' . strlen($payload),
        'project-id: ' . getenv('NOMA_PROJECT_ID'),
        'Authorization: Bearer ' . getenv('NOMA_API_KEY'),
        'Accept: application/json',
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
echo curl_exec($ch);
curl -sS -X POST "https://app.nomacms.com/api/collections" \
  -H "Content-Type: application/json" \
  -H "project-id: $NOMA_PROJECT_ID" \
  -H "Authorization: Bearer $NOMA_API_KEY" \
  -H "Accept: application/json" \
  -d '{"name":"Products","slug":"products","is_singleton":false,"fields":[{"type":"text","label":"Title","name":"title","validations":{"required":{"status":true,"message":"Title is required"}}}]}'
package main
 
import (
	"bytes"
	"encoding/json"
	"io"
	"net/http"
	"os"
)
 
func main() {
	body := map[string]any{
		"name":         "Products",
		"slug":         "products",
		"is_singleton": false,
		"fields": []any{
			map[string]any{
				"type":  "text",
				"label": "Title",
				"name":  "title",
				"validations": map[string]any{
					"required": map[string]any{"status": true, "message": "Title is required"},
				},
			},
		},
	}
	raw, _ := json.Marshal(body)
	req, err := http.NewRequest("POST", "https://app.nomacms.com/api/collections", bytes.NewReader(raw))
	if err != nil {
		panic(err)
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("project-id", os.Getenv("NOMA_PROJECT_ID"))
	req.Header.Set("Authorization", "Bearer "+os.Getenv("NOMA_API_KEY"))
	req.Header.Set("Accept", "application/json")
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	_, _ = io.Copy(os.Stdout, res.Body)
}
require "net/http"
require "json"
require "uri"
 
uri = URI("https://app.nomacms.com/api/collections")
payload = {
  "name" => "Products",
  "slug" => "products",
  "is_singleton" => false,
  "fields" => [
    {
      "type" => "text",
      "label" => "Title",
      "name" => "title",
      "validations" => {
        "required" => { "status" => true, "message" => "Title is required" }
      }
    }
  ]
}
req = Net::HTTP::Post.new(uri)
req["Content-Type"] = "application/json"
req["project-id"] = ENV.fetch("NOMA_PROJECT_ID")
req["Authorization"] = "Bearer #{ENV.fetch('NOMA_API_KEY')}"
req["Accept"] = "application/json"
req.body = JSON.generate(payload)
 
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  puts http.request(req).body
end
import json
import os
import urllib.request
 
payload = {
    "name": "Products",
    "slug": "products",
    "is_singleton": False,
    "fields": [
        {
            "type": "text",
            "label": "Title",
            "name": "title",
            "validations": {
                "required": {"status": True, "message": "Title is required"},
            },
        }
    ],
}
data = json.dumps(payload).encode()
req = urllib.request.Request(
    "https://app.nomacms.com/api/collections",
    data=data,
    headers={
        "Content-Type": "application/json",
        "project-id": os.environ["NOMA_PROJECT_ID"],
        "Authorization": f"Bearer {os.environ['NOMA_API_KEY']}",
        "Accept": "application/json",
    },
    method="POST",
)
with urllib.request.urlopen(req) as res:
    print(res.read().decode())
  • Authentication - Abilities (admin)
  • Create a Field - Add fields after creation (HTTP)
  • Fields (JS SDK) - fields.create and related helpers
  • List Collections - See all collections
  • JavaScript SDK - collections.create

Search documentation

Find guides and reference pages