HTTP routes
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
| Caller | Meaning |
|---|---|
| Public | Anyone. No session is looked up |
| Content | Anyone. The access rules decide. Writes pass the CSRF check. An API key works with a grant for the target |
| Session | A signed-in user. An API key gets 403, except where noted |
| Admin | A signed-in admin |
| Secret | Authorization: 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
| Method | Path | Caller | What it does |
|---|---|---|---|
GET | /collections/:name | Content | Lists documents. Every other query key is a where filter |
GET | /collections/:name/:id | Content | Reads one document. 404 when it is missing |
POST | /collections/:name | Content | Creates a document. 201 |
POST | /collections/:name/draft | Content | Creates a draft. 201 |
PUT | /collections/:name/:id | Content | Saves and publishes |
PUT | /collections/:name/:id/draft | Content | Saves a draft |
POST | /collections/:name/:id/publish | Content | Publishes the draft |
POST | /collections/:name/:id/unpublish | Content | Takes the document offline |
DELETE | /collections/:name/:id/draft | Content | Discards the draft. 204 when it deleted a document that was never published |
DELETE | /collections/:name/:id | Content | Deletes. 204 |
POST | /collections/:name/:id/duplicate | Content | Copies a document. 201 |
POST | /collections/:name/:id/schedule | Content | Body { action, at, locale? }. Returns { id } of the job |
POST | /collections/:name/:id/locales/:to/copy | Content | Body { from }. Copies one language into another |
DELETE | /collections/:name/:id/locales/:locale | Content | Removes one language |
POST | /collections/:name/:id/structure | Content | Body { sync, locale?, dryRun? } |
POST | /collections/:name/structure/apply | Content | Body { dryRun? } |
POST | /collections/:name/preview-url | Session | The 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
| Method | Path | Caller | What it does |
|---|---|---|---|
GET | /globals/:name | Content | Reads a global |
PUT | /globals/:name | Content | Saves and publishes |
PUT | /globals/:name/draft | Content | Saves a draft |
POST | /globals/:name/publish | Content | Publishes the draft |
POST | /globals/:name/unpublish | Content | Takes the global offline |
DELETE | /globals/:name/draft | Content | Discards the draft |
POST | /globals/:name/schedule | Content | Body { action, at, locale? } |
POST | /globals/:name/locales/:to/copy | Content | Body { from } |
DELETE | /globals/:name/locales/:locale | Content | Removes one language |
POST | /globals/:name/structure | Content | Body { sync, locale?, dryRun? } |
POST | /globals/:name/preview-url | Session | Returns { url } |
Versions and locks
These need a session and the update rule of the document or global.
| Method | Path | What it does |
|---|---|---|
GET | /collections/:name/:id/versions | Lists the versions |
GET | /collections/:name/:id/versions/:version | Reads one version |
POST | /collections/:name/:id/versions/:version/restore | Makes the version the draft |
GET | /globals/:name/versions, /globals/:name/versions/:version | The same for a global |
POST | /globals/:name/versions/:version/restore | The same for a global |
POST | /collections/:name/:id/lock, /globals/:name/lock | Body { takeover? }. Takes or renews the edit lock for 90 seconds |
DELETE | /collections/:name/:id/lock, /globals/:name/lock | Frees your lock. 204 |
Media
These exist while the media library is on. media.access decides who may call the content routes.
| Method | Path | Caller | What it does |
|---|---|---|---|
GET | /media/files/:key | Public | The original file. Checks media.access.read when it is set |
GET | /media/img/:modifiers/:key | Public | An image variant. Renders it on the first request with ipx() or cloudflare() |
GET | /media/thumbnail/:key | Public | The admin's preview image, without media.images |
GET | /media/folders | Content | The folders of the files you may read |
GET | /media/download?id=&folder= | Content | One file as a download, or several as a ZIP |
POST | /media/uploads | Content | Body { filename, size, mimeType, folder }. Starts an upload in parts. 201 |
PUT | /media/uploads/:id/parts/:n | Content | Sends one part |
POST | /media/uploads/:id/complete | Content | Body { parts }. Finishes the upload. 201 |
DELETE | /media/uploads/:id | Content | Cancels the upload |
PATCH | /media/:id | Content | Body { alt?, filename?, folder? }. A new name or folder moves the file |
POST | /media/folders/rename | Content | Body { from, to } |
POST | /media/:id/regenerate | Content | Body { force? }. Renders the variants again |
PUT | /media/:id/thumbnail | Content | A WebP or JPEG body. Sets the preview image |
DELETE | /media/:id | Content | Deletes 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.
| Method | Path | Caller | What it does |
|---|---|---|---|
GET | /auth-status | Public | Which sign-in methods are on, and whether setup is needed |
GET | /auth/sign-in-link?token= | Public | Signs in with a link from tenon users recover or cms.users.signInLink() |
POST | /setup | Public | Body { name, email }. Creates the first admin, when password sign-in is off |
POST | /account/password | Session | Body { newPassword }. Sets a first password |
POST | /invites/check | Public | Body { token }. The email and role of an invite |
POST | /invites/accept | Public | Body { token, name, password? }. Creates the user and signs in |
GET | /invites | Admin | Lists the invites |
POST | /invites | Admin | Body { email, role, url? }. 502 when the email failed |
POST | /invites/:id/resend | Admin | Body { url } |
DELETE | /invites/:id | Admin | Revokes the invite |
GET | /api-keys | Admin | Lists the API keys |
POST | /api-keys | Admin | Body { name, permissions, expiresIn? }. Returns the key once |
POST | /api-keys/:id/roll | Admin | A new key for the same permissions |
POST | /api-keys/:id/revoke | Admin | Revokes the key |
DELETE | /api-keys/:id | Admin | Deletes 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
| Method | Path | Caller | What it does |
|---|---|---|---|
GET | /jobs | Session | Query id, status, task, target, docId, limit |
GET | /jobs/cron | Session | The cron entries with their next and last run |
POST | /jobs/:id/run | Session | Runs a queued or failed job now |
POST | /jobs/:id/retry | Session | Queues a failed job again |
DELETE | /jobs/:id | Session | Cancels a job |
GET, POST | /jobs/run | Secret | Runs 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.
| Method | Path | What it does |
|---|---|---|
GET | /export?media=&scope= | Streams the ZIP |
GET | /export/summary | What an export would hold |
POST | /export | Returns { url }, a download link |
POST | /import?mode= | A ZIP body. Imports it |
POST | /import/check | Body { manifest, mode? }. Checks an archive |
POST | /import/uploads | Starts an import in parts |
PUT | /import/uploads/:id/parts/:n | Sends one part |
POST | /import/uploads/:id/complete?mode= | Body { parts }. Runs the import |
DELETE | /import/uploads/:id | Cancels the import |
See Backup and restore.
Schema, preview and admin
| Method | Path | Caller | What it does |
|---|---|---|---|
GET | /schema | Session | The schema the user may see. Also an API key with read on schema |
GET | /localization | Public | The locales and the default locale, or null |
POST | /preview | Session | Body { perspective? }. Sets the preview cookie. 204 |
DELETE | /preview | Session | Clears the preview cookie. 204 |
GET | /admin-bar?url=&mode=&locale= | Session | The items of the admin bar for a page |
GET | /admin-brand | Public | The logo, icon and name for the sign-in page |
POST | /admin/load | Session | Runs the load of a custom field, page or bar item |
POST | /admin/actions/:key | Session | Runs an action. Returns { message } |
POST | /admin/links/resolve | Session | Resolves link references |
GET | /admin/links/search?query= | Session | Searches 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
| Method | Path | What it does |
|---|---|---|
GET | /sitemap.xml | The sitemap, unless sitemap: false |
GET | /robots.txt | The robots file, unless robots: false |
Status codes
| Status | Means |
|---|---|
400 | Invalid data or query. errors holds one message per field |
401 | No session, or an unknown API key |
403 | The access rule denies, the CSRF check failed, or an API key cannot use the route |
404 | The document, file or route does not exist |
409 | A conflict. code is CHANGED or LINKED_CONTENT, or references lists the documents that block a delete |
415 | The body is not JSON where only JSON is allowed |
500 | An 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.
Related resources
- Client: the methods that call these routes.
- HTTP API and client: a guide to the read and write routes.