Noma

Create a Field

Create a Field

Adds a field to an existing collection. Use this to extend a schema after creating a collection or to add fields without recreating the collection.

Request

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

{collection} is the collection slug (for example blog-posts).

Requires the admin ability on the token.

JSON body

FieldTypeRequiredDescription
typestringYesField type (max 60 characters), for example text, group, relation
labelstringYesEditor label (max 60 characters)
namestringYesUnique within the same parent: same collection and same parent_field_id. Lowercase letters, digits, and hyphens: ^[a-z0-9]+(?:-[a-z0-9]+)*$
descriptionstringNoHelp text
placeholderstringNoPlaceholder
optionsobjectNoType-specific options. For relation fields, options.relation can reference another collection by slug string or legacy collection_id (normalized to an internal id in the stored options).
validationsobjectNoValidation rules (for example required)
parent_field_idnumber | nullNoSet to the database id of a group field in this collection to create a nested field. Omit or null for top-level fields. For type: "group", the API forces parent_field_id to null.

Group fields (type: "group")

You must send options.repeatable as a boolean (true or false).

Uniqueness

name is unique per (collection, parent). You can reuse the same name under a different group because parent_field_id differs.

Response (201)

JSON object for the new field:

FieldTypeDescription
uuidstringField UUID (use this in Update a Field and Delete a Field URLs)
typestringField type
labelstringLabel
namestringAPI name
descriptionstring | nullDescription
placeholderstring | nullPlaceholder
optionsobjectOptions (relation targets are stored with resolved collection ids)
validationsobjectValidations
ordernumberSort order among siblings
parent_field_idnumber | nullParent group field id, if any
created_atstringTimestamp
updated_atstringTimestamp

This matches a single element in the fields array from List Collections. List responses may include a numeric id on each field; create/update/delete responses here emphasize uuid for the field identity in these routes.

Errors

StatusWhen
400Missing project-id or project cannot be resolved
401Missing or invalid bearer token
403Token does not have admin (or *)
404Collection slug not found (Collection not found.)
422Validation failed (duplicate name, invalid parent_field_id, unknown relation collection, missing options.repeatable for group, 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 field = await client.fields.create("blog-posts", {
  type: "text",
  label: "Subtitle",
  name: "subtitle",
  options: {},
  validations: {},
})
 
console.log(field)
import axios from "axios"
 
async function main() {
  const { data } = await axios.post(
    "https://app.nomacms.com/api/collections/blog-posts/fields",
    {
      type: "text",
      label: "Subtitle",
      name: "subtitle",
    },
    {
      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([
    'type' => 'text',
    'label' => 'Subtitle',
    'name' => 'subtitle',
]);
 
$ch = curl_init('https://app.nomacms.com/api/collections/blog-posts/fields');
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/blog-posts/fields" \
  -H "Content-Type: application/json" \
  -H "project-id: $NOMA_PROJECT_ID" \
  -H "Authorization: Bearer $NOMA_API_KEY" \
  -H "Accept: application/json" \
  -d '{"type":"text","label":"Subtitle","name":"subtitle"}'
package main
 
import (
	"bytes"
	"encoding/json"
	"io"
	"net/http"
	"os"
)
 
func main() {
	body := map[string]any{
		"type":  "text",
		"label": "Subtitle",
		"name":  "subtitle",
	}
	raw, _ := json.Marshal(body)
	req, err := http.NewRequest("POST", "https://app.nomacms.com/api/collections/blog-posts/fields", 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/blog-posts/fields")
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({ "type" => "text", "label" => "Subtitle", "name" => "subtitle" })
 
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 = {"type": "text", "label": "Subtitle", "name": "subtitle"}
data = json.dumps(payload).encode()
req = urllib.request.Request(
    "https://app.nomacms.com/api/collections/blog-posts/fields",
    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)
  • Get a Collection - Read current fields
  • Update a Field - Change an existing field
  • JavaScript SDK - fields.create

Search documentation

Find guides and reference pages