Delete a Collection
Permanently deletes a collection and all of its fields and content entries for that project.
The request must include a JSON body that confirms the slug being deleted (safety check).
Request
DELETE /api/collections/{slug} HTTP/1.1
Host: app.nomacms.com
Content-Type: application/json
project-id: <project-uuid>
Authorization: Bearer <api-token>Replace {slug} in the path with the collection to delete.
Requires the admin ability on the token.
JSON body
| Field | Type | Required | Description |
|---|---|---|---|
slug | string | Yes | Must exactly match the slug in the URL path |
If slug does not match the collection in the path, the API responds with 422 (The collection slug does not match.).
Raw HTTP clients must send Content-Type: application/json and a JSON body. The JavaScript SDK includes { slug } for you when you call collections.delete(slug).
Response (204)
No response body.
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 | slug missing or does not match the path |
| 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!,
})
await client.collections.delete("old-collection")import axios from "axios"
async function main() {
const slug = "old-collection"
const res = await axios.delete(`https://app.nomacms.com/api/collections/${encodeURIComponent(slug)}`, {
headers: {
"Content-Type": "application/json",
"project-id": process.env.NOMA_PROJECT_ID!,
Authorization: `Bearer ${process.env.NOMA_API_KEY}`,
},
data: { slug },
})
console.log(res.status)
}
void main()<?php
$slug = 'old-collection';
$payload = json_encode(['slug' => $slug]);
$ch = curl_init('https://app.nomacms.com/api/collections/' . rawurlencode($slug));
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'DELETE',
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'),
],
CURLOPT_RETURNTRANSFER => true,
]);
curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE);curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE "https://app.nomacms.com/api/collections/old-collection" \
-H "Content-Type: application/json" \
-H "project-id: $NOMA_PROJECT_ID" \
-H "Authorization: Bearer $NOMA_API_KEY" \
-d '{"slug":"old-collection"}'package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
slug := "old-collection"
raw, _ := json.Marshal(map[string]string{"slug": slug})
req, err := http.NewRequest(
"DELETE",
"https://app.nomacms.com/api/collections/"+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"))
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
fmt.Println(res.StatusCode)
}require "net/http"
require "json"
require "uri"
slug = "old-collection"
uri = URI("https://app.nomacms.com/api/collections/#{slug}")
req = Net::HTTP::Delete.new(uri)
req["Content-Type"] = "application/json"
req["project-id"] = ENV.fetch("NOMA_PROJECT_ID")
req["Authorization"] = "Bearer #{ENV.fetch('NOMA_API_KEY')}"
req.body = JSON.generate({ "slug" => slug })
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
res = http.request(req)
puts res.code
endimport json
import os
import urllib.parse
import urllib.request
slug = "old-collection"
path = "/api/collections/" + urllib.parse.quote(slug, safe="")
payload = json.dumps({"slug": slug}).encode()
req = urllib.request.Request(
"https://app.nomacms.com" + path,
data=payload,
headers={
"Content-Type": "application/json",
"project-id": os.environ["NOMA_PROJECT_ID"],
"Authorization": f"Bearer {os.environ['NOMA_API_KEY']}",
},
method="DELETE",
)
with urllib.request.urlopen(req) as res:
print(res.status)Related
- Authentication - Abilities (
admin) - Update a Collection - Rename instead of delete when possible
- JavaScript SDK -
collections.delete