Content API

Every site serves its own content API and form endpoint. How to read content in your pages, post forms from your own code, and what the admin API offers.

Every Tandmade site runs its own small backend: content, form submissions and media live in the site's database, and the site answers for them under /_cms/*, /_forms/* and /_media/*. The editor is one client of that API; the data belongs to the site.

Read content in your pages

Pages and components read collections through Astro.locals.cms. A page that renders on request shows a published change right away, without a rebuild.

src/pages/blog/[slug].astro

---
export const prerender = false;
import Layout from "../../layouts/Layout.astro";
import { collectionEntry, localize } from "@expirio/cms";

const found = await collectionEntry(Astro.locals.cms, "blog", Astro.params.slug);
if (!found) return new Response(null, { status: 404 });
const post = localize(found, Astro.currentLocale);
---
<Layout title={post.data.title}>
  <h1>{post.data.title}</h1>
</Layout>

For a list with filters, search, sorting and pages, use collectionQuery(Astro.locals.cms, "blog", Astro.url.searchParams, { perPage: 24 }); it returns entries, total, page and pages. The live site returns only published items. Collection keys and field names come from src/cms.config.ts.

Post a form from JavaScript

A form posts to /_forms/ plus its key, the end of its action. A plain HTML form gets a redirect. To get JSON back, send Accept: application/json:

const res = await fetch("/_forms/contact", {
  method: "POST",
  headers: { Accept: "application/json" },
  body: new FormData(form),
});
const result = await res.json();
// 200 → { "ok": true, "id": "…" }
// 422 → { "error": "Check the highlighted fields.", "errors": { "email": "Enter a valid email address." } }

The endpoint checks fields against the form's HTML, drops fields that aren't in it, refuses posts from other websites, answers 429 when one visitor sends too many, and accepts only POST. It needs no key.

Generated routes

Route What it serves
/_media/… Images and files uploaded in the editor
/sitemap-cms.xml Published collection items
/robots.txt, /llms.txt Generated from the site settings, unless the site has its own

The admin API

This is how Tandmade reads and writes the site's content. Every request needs the site's access key:

curl -H "Authorization: Bearer $KEY" "https://example.com/_cms/entries?collection=blog&limit=10"

Tandmade creates the key when the site is first published and keeps it; it isn't shown in the editor. The preview has its own key.

Route Methods
/_cms/schema GET — collections, fields, item counts
/_cms/entries?collection=… GET — items, drafts included; POST — new item
/_cms/entries/{id} GET, PATCH (data, slug or status), DELETE
/_cms/entries/{id}/versions GET — history; POST — restore a version
/_cms/entries/{id}/translate POST — create a translation
/_cms/forms GET — the site's forms
/_cms/submissions?form=… GET — submissions, newest first
/_cms/submissions/{id} GET, PATCH (status), DELETE
/_cms/assets, /_cms/assets/{id} Uploaded media

GET /_cms/entries takes collection (required), q, where (JSON of field values), orderBy (field, -field or updated), limit, offset and locale.

Most people want MCP To change content from your own AI agent or scripts, connect through MCP instead: it signs in with your account, keeps drafts as drafts and records every change. See MCP in depth.

Reset access

If you think someone got hold of the site's key, open Forms › Settings › Advanced on a published site and click Reset access. The old key stops working at once; the editor keeps working. Only your team sees it, not content editors or clients.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.