API

HTTP routes

Every route under /_tenon, who may call it, and the status codes it answers.

Tenon serves its API under /_tenon, in your app. The client calls these routes for you. The paths below are relative to /_tenon.

Who may call a route

CallerMeaning
PublicAnyone. No session is looked up
ContentAnyone. The access rules decide. Writes pass the CSRF check. An API key works with a grant for the target
SessionA signed-in user. An API key gets 403, except where noted
AdminA signed-in admin
SecretAuthorization: Bearer <jobs.secret>

The CSRF check refuses a write from another origin with a form or text body. A JSON body, a ZIP body and a request with x-api-key pass. A refused request answers 403.

Collections

MethodPathCallerWhat it does
GET/collections/:nameContentLists documents. Every other query key is a where filter
GET/collections/:name/:idContentReads one document. 404 when it is missing
POST/collections/:nameContentCreates a document. 201
POST/collections/:name/draftContentCreates a draft. 201
PUT/collections/:name/:idContentSaves and publishes
PUT/collections/:name/:id/draftContentSaves a draft
POST/collections/:name/:id/publishContentPublishes the draft
POST/collections/:name/:id/unpublishContentTakes the document offline
DELETE/collections/:name/:id/draftContentDiscards the draft. 204 when it deleted a document that was never published
DELETE/collections/:name/:idContentDeletes. 204
POST/collections/:name/:id/duplicateContentCopies a document. 201
POST/collections/:name/:id/scheduleContentBody { action, at, locale? }. Returns { id } of the job
POST/collections/:name/:id/locales/:to/copyContentBody { from }. Copies one language into another
DELETE/collections/:name/:id/locales/:localeContentRemoves one language
POST/collections/:name/:id/structureContentBody { sync, locale?, dryRun? }
POST/collections/:name/structure/applyContentBody { dryRun? }
POST/collections/:name/preview-urlSessionThe preview URL of unsaved data. Returns { url }

The read routes take the read options as query parameters: limit, populate, depth, select, locale, fallback, permalink and alternates. populate and select take dot paths, like select=title,seo.title. The write routes take ?locale=, ?updatedAt=, ?allowBrokenLinks=true and ?all=true where the local method has the option.

Globals

MethodPathCallerWhat it does
GET/globals/:nameContentReads a global
PUT/globals/:nameContentSaves and publishes
PUT/globals/:name/draftContentSaves a draft
POST/globals/:name/publishContentPublishes the draft
POST/globals/:name/unpublishContentTakes the global offline
DELETE/globals/:name/draftContentDiscards the draft
POST/globals/:name/scheduleContentBody { action, at, locale? }
POST/globals/:name/locales/:to/copyContentBody { from }
DELETE/globals/:name/locales/:localeContentRemoves one language
POST/globals/:name/structureContentBody { sync, locale?, dryRun? }
POST/globals/:name/preview-urlSessionReturns { url }

Versions and locks

These need a session and the update rule of the document or global.

MethodPathWhat it does
GET/collections/:name/:id/versionsLists the versions
GET/collections/:name/:id/versions/:versionReads one version
POST/collections/:name/:id/versions/:version/restoreMakes the version the draft
GET/globals/:name/versions, /globals/:name/versions/:versionThe same for a global
POST/globals/:name/versions/:version/restoreThe same for a global
POST/collections/:name/:id/lock, /globals/:name/lockBody { takeover? }. Takes or renews the edit lock for 90 seconds
DELETE/collections/:name/:id/lock, /globals/:name/lockFrees your lock. 204

Media

These exist while the media library is on. media.access decides who may call the content routes.

MethodPathCallerWhat it does
GET/media/files/:keyPublicThe original file. Checks media.access.read when it is set
GET/media/img/:modifiers/:keyPublicAn image variant. Renders it on the first request with ipx() or cloudflare()
GET/media/thumbnail/:keyPublicThe admin's preview image, without media.images
GET/media/foldersContentThe folders of the files you may read
GET/media/download?id=&folder=ContentOne file as a download, or several as a ZIP
POST/media/uploadsContentBody { filename, size, mimeType, folder }. Starts an upload in parts. 201
PUT/media/uploads/:id/parts/:nContentSends one part
POST/media/uploads/:id/completeContentBody { parts }. Finishes the upload. 201
DELETE/media/uploads/:idContentCancels the upload
PATCH/media/:idContentBody { alt?, filename?, folder? }. A new name or folder moves the file
POST/media/folders/renameContentBody { from, to }
POST/media/:id/regenerateContentBody { force? }. Renders the variants again
PUT/media/:id/thumbnailContentA WebP or JPEG body. Sets the preview image
DELETE/media/:idContentDeletes the file. 204

GET /collections/media lists the files. The other collection routes refuse to write to media.

Users and sign-in

better-auth answers every route under /auth, like POST /auth/sign-in/email, POST /auth/sign-out and GET /auth/get-session. Its errors have its own body. See Authentication.

MethodPathCallerWhat it does
GET/auth-statusPublicWhich sign-in methods are on, and whether setup is needed
GET/auth/sign-in-link?token=PublicSigns in with a link from tenon users recover or cms.users.signInLink()
POST/setupPublicBody { name, email }. Creates the first admin, when password sign-in is off
POST/account/passwordSessionBody { newPassword }. Sets a first password
POST/invites/checkPublicBody { token }. The email and role of an invite
POST/invites/acceptPublicBody { token, name, password? }. Creates the user and signs in
GET/invitesAdminLists the invites
POST/invitesAdminBody { email, role, url? }. 502 when the email failed
POST/invites/:id/resendAdminBody { url }
DELETE/invites/:idAdminRevokes the invite
GET/api-keysAdminLists the API keys
POST/api-keysAdminBody { name, permissions, expiresIn? }. Returns the key once
POST/api-keys/:id/rollAdminA new key for the same permissions
POST/api-keys/:id/revokeAdminRevokes the key
DELETE/api-keys/:idAdminDeletes the key

The public routes that sign someone in accept only JSON, and answer 415 for any other body. User management runs through better-auth's admin routes under /auth/admin, for admins only.

Jobs

MethodPathCallerWhat it does
GET/jobsSessionQuery id, status, task, target, docId, limit
GET/jobs/cronSessionThe cron entries with their next and last run
POST/jobs/:id/runSessionRuns a queued or failed job now
POST/jobs/:id/retrySessionQueues a failed job again
DELETE/jobs/:idSessionCancels a job
GET, POST/jobs/runSecretRuns the due jobs. Returns { ran, next }. Only with jobs.secret

Each job route also checks the access of the task. See Manage jobs.

Export and import

An admin, or an API key with a grant on backup, may call these: read to export, update to import.

MethodPathWhat it does
GET/export?media=&scope=Streams the ZIP
GET/export/summaryWhat an export would hold
POST/exportReturns { url }, a download link
POST/import?mode=A ZIP body. Imports it
POST/import/checkBody { manifest, mode? }. Checks an archive
POST/import/uploadsStarts an import in parts
PUT/import/uploads/:id/parts/:nSends one part
POST/import/uploads/:id/complete?mode=Body { parts }. Runs the import
DELETE/import/uploads/:idCancels the import

See Backup and restore.

Schema, preview and admin

MethodPathCallerWhat it does
GET/schemaSessionThe schema the user may see. Also an API key with read on schema
GET/localizationPublicThe locales and the default locale, or null
POST/previewSessionBody { perspective? }. Sets the preview cookie. 204
DELETE/previewSessionClears the preview cookie. 204
GET/admin-bar?url=&mode=&locale=SessionThe items of the admin bar for a page
GET/admin-brandPublicThe logo, icon and name for the sign-in page
POST/admin/loadSessionRuns the load of a custom field, page or bar item
POST/admin/actions/:keySessionRuns an action. Returns { message }
POST/admin/links/resolveSessionResolves link references
GET/admin/links/search?query=SessionSearches link targets by title

The admin routes exist only while the admin is on.

Plugin routes

A plugin's publicRoutes and routes mount under /<plugin name>. publicRoutes are public. routes need a session, and API keys get 403. See Plugins.

Outside /_tenon

MethodPathWhat it does
GET/sitemap.xmlThe sitemap, unless sitemap: false
GET/robots.txtThe robots file, unless robots: false

Status codes

StatusMeans
400Invalid data or query. errors holds one message per field
401No session, or an unknown API key
403The access rule denies, the CSRF check failed, or an API key cannot use the route
404The document, file or route does not exist
409A conflict. code is CHANGED or LINKED_CONTENT, or references lists the documents that block a delete
415The body is not JSON where only JSON is allowed
500An unexpected error. afterError sees it

Without a session, an unknown path under /_tenon answers 401, not 404. See Errors and types for the error body.