Noma

Create an Entry

Create an Entry

Creates a new content entry in a collection.

Request

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

Requires the create ability on the token.

Path parameters

ParamDescription
collectionCollection slug

JSON body

FieldTypeRequiredDescription
localestringYes*Must be one of the project’s configured locales. If omitted, the API sets locale to the project default_locale before validation.
statestringNodraft or published. Default draft. Invalid values become draft. When state is published, the server sets published_at automatically if it was empty.
dataobjectNoField values keyed by field name. Unknown keys are ignored. Omitted fields are left empty.

*Effectively required by validation rules; defaulting uses the project default locale when the client omits locale.

Singleton collections: If the collection already has an entry (for the requested locale when locale is set), the API responds with 422 (This collection is a singleton and already has an entry.).

Field values follow the same shapes as updates (groups, repeatables, relations, and so on). Validation is driven by each field’s schema (required, unique, and so on).

Response (201)

JSON object: created entry in ContentEntryResource shape (uuid, locale, published_at, fields). Optional created_at / updated_at when timestamps is passed as a query parameter on the request (same as list/get).

The state field is not included in the response body.

Errors

StatusWhen
400Missing project-id or project cannot be resolved
401Missing or invalid bearer token
403Token does not have create (or *), or controller rejects the token
404Collection not found
422Validation failed, or singleton already has an entry

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.content.create("blog-posts", {
  locale: "en",
  state: "draft",
  data: {
    title: "Hello",
    slug: "hello",
    content: "<p>...</p>",
  },
})
 
console.log(created)
import axios from "axios"
 
async function main() {
  const { data } = await axios.post(
    "https://app.nomacms.com/api/blog-posts",
    {
      locale: "en",
      state: "draft",
      data: {
        title: "Hello",
        slug: "hello",
        content: "<p>...</p>",
      },
    },
    {
      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([
    'locale' => 'en',
    'state' => 'draft',
    'data' => [
        'title' => 'Hello',
        'slug' => 'hello',
        'content' => '<p>...</p>',
    ],
]);
 
$ch = curl_init('https://app.nomacms.com/api/blog-posts');
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/blog-posts" \
  -H "Content-Type: application/json" \
  -H "project-id: $NOMA_PROJECT_ID" \
  -H "Authorization: Bearer $NOMA_API_KEY" \
  -H "Accept: application/json" \
  -d '{"locale":"en","state":"draft","data":{"title":"Hello","slug":"hello","content":"<p>...</p>"}}'
package main
 
import (
	"bytes"
	"encoding/json"
	"io"
	"net/http"
	"os"
)
 
func main() {
	body := map[string]any{
		"locale": "en",
		"state":  "draft",
		"data": map[string]any{
			"title":   "Hello",
			"slug":    "hello",
			"content": "<p>...</p>",
		},
	}
	raw, err := json.Marshal(body)
	if err != nil {
		panic(err)
	}
	req, err := http.NewRequest("POST", "https://app.nomacms.com/api/blog-posts", 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/blog-posts")
payload = {
  "locale" => "en",
  "state" => "draft",
  "data" => {
    "title" => "Hello",
    "slug" => "hello",
    "content" => "<p>...</p>"
  }
}
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 = {
    "locale": "en",
    "state": "draft",
    "data": {
        "title": "Hello",
        "slug": "hello",
        "content": "<p>...</p>",
    },
}
data = json.dumps(payload).encode()
req = urllib.request.Request(
    "https://app.nomacms.com/api/blog-posts",
    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())
  • Update an Entry - PUT vs PATCH
  • Bulk operations - Create many entries
  • Get a Collection - Field definitions for data keys
  • JavaScript SDK - content.create

Search documentation

Find guides and reference pages