Update a Collection
Updates a collection's name and slug. The request body must include both fields on every call, even if only one value changes.
Changing the slug updates relation field options that pointed at the old slug so they reference the collection correctly.
Request
PUT /api/collections/{slug} HTTP/1.1
Host: app.nomacms.com
Content-Type: application/json
project-id: <project-uuid>
Authorization: Bearer <api-token>
Accept: application/json{slug} is the collection's current slug in the URL path.
Requires the admin ability on the token.
JSON body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | New display name (max 60 characters) |
slug | string | Yes | New slug (max 60); same uniqueness and reserved rules as Create a Collection |
Reserved slugs: collections, files, webhooks. The new slug must remain unique within the project.
Slug renames and relations
If slug changes, relation fields in other collections that referenced the old slug are updated to point at the renamed collection (internal ids in stored options).
Response (200)
JSON object with uuid, name, slug, is_singleton, created_at, updated_at. The fields key is not included on this response (field definitions are unchanged here; use Get a Collection or List Collections to read them).
Errors
| Status | When |
|---|---|
| 400 | Missing project-id or project cannot be resolved |
| 401 | Missing or invalid bearer token |
| 403 | Token does not have admin (or *) |
| 404 | Unknown collection slug (Collection not found.) or no project with that UUID |
| 422 | Validation failed (duplicate slug, reserved slug, and so on) |
| 429 | Rate limited |
Example
import { createClient } from "@nomacms/js-sdk"
const client = createClient({
projectId: process.env.NOMA_PROJECT_ID!,
apiKey: process.env.NOMA_API_KEY!,
})
const updated = await client.collections.update("old-slug", {
name: "New Name",
slug: "new-slug",
})
console.log(updated)import axios from "axios"
async function main() {
const { data } = await axios.put(
"https://app.nomacms.com/api/collections/old-slug",
{ name: "New Name", slug: "new-slug" },
{
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
$current = 'old-slug';
$payload = json_encode(['name' => 'New Name', 'slug' => 'new-slug']);
$ch = curl_init('https://app.nomacms.com/api/collections/' . rawurlencode($current));
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'PUT',
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 PUT "https://app.nomacms.com/api/collections/old-slug" \
-H "Content-Type: application/json" \
-H "project-id: $NOMA_PROJECT_ID" \
-H "Authorization: Bearer $NOMA_API_KEY" \
-H "Accept: application/json" \
-d '{"name":"New Name","slug":"new-slug"}'package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
)
func main() {
raw, _ := json.Marshal(map[string]string{"name": "New Name", "slug": "new-slug"})
req, err := http.NewRequest("PUT", "https://app.nomacms.com/api/collections/old-slug", 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/old-slug")
req = Net::HTTP::Put.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({ "name" => "New Name", "slug" => "new-slug" })
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
puts http.request(req).body
endimport json
import os
import urllib.request
payload = json.dumps({"name": "New Name", "slug": "new-slug"}).encode()
req = urllib.request.Request(
"https://app.nomacms.com/api/collections/old-slug",
data=payload,
headers={
"Content-Type": "application/json",
"project-id": os.environ["NOMA_PROJECT_ID"],
"Authorization": f"Bearer {os.environ['NOMA_API_KEY']}",
"Accept": "application/json",
},
method="PUT",
)
with urllib.request.urlopen(req) as res:
print(res.read().decode())Related
- Authentication - Abilities (
admin) - Create a Collection - Slug rules
- Get a Collection - Read fields after update
- JavaScript SDK -
collections.update