Skip to content

Latest commit

 

History

History
682 lines (503 loc) · 21.7 KB

API_DOCUMENTATION.md

File metadata and controls

682 lines (503 loc) · 21.7 KB

TuxCMS API

Everything lives under /api/v1. Responses are always JSON, whatever the request's Accept header says.

Conventions

Envelope. Successful responses put the payload in data. Writes usually add a message. Lists add meta with current_page, last_page and total (most also include per_page).

Auth. Endpoints marked token need Authorization: Bearer <token>. Without one they answer 401 with {"message": "Unauthenticated."}.

Errors. Validation failures answer 422:

{
  "message": "The title field is required.",
  "errors": { "title": ["The title field is required."] }
}

A missing record is 404. Throttled endpoints answer 429 when the limit is passed.

Dates are ISO 8601 strings.

Authentication

There is no registration endpoint. Accounts are made on the server with php artisan user:create --role=<role>, or by an admin with POST /users.

Every change below needs a permission, which the account's role grants (see Users and roles). Without it the API answers 403. Reads need only a token, except the inbox (enquiries and job applications), which needs read inbox.

POST /auth/login

Throttled to 5 a minute.

{ "email": "editor@example.com", "password": "secret-password" }
{
  "data": { "id": 1, "name": "Editor", "email": "editor@example.com" },
  "token": "1|abc...",
  "message": "Login successful"
}

Wrong credentials answer 401 with {"message": "Invalid credentials"}.

data also carries role (admin, editor, author or viewer), is_owner (whether this is the overall admin) and permissions.

POST /auth/logout (token)

Revokes the token the request was made with.

GET /auth/me (token)

The signed-in user.

Pages

The read endpoints are open, so the public site and the builder need no token. They behave differently with one: a visitor sees only published pages and visible sections, an editor sees drafts and hidden sections too. A page counts as published when its status is published and published_at is empty or in the past.

The page object

{
  "id": 4,
  "title": "Web design",
  "slug": "web-design",
  "path": "/services/web-design",
  "full_path": "/services/web-design",
  "content": null,
  "excerpt": "Sites that load fast.",
  "template": "crystal",
  "status": "published",
  "is_scheduled": false,
  "order": 2,
  "is_homepage": false,
  "show_in_nav": true,
  "nav_label": null,
  "custom_fields": null,
  "published_at": "2026-11-11T09:00:00+00:00",
  "created_at": "2026-11-10T14:02:11+00:00",
  "updated_at": "2026-11-24T16:40:03+00:00"
}

is_scheduled is true for a published page dated in the future. author, parent, children, sections, seo, featured_image and gallery appear when the endpoint loads them.

A section:

{
  "id": 40,
  "key": "hero",
  "type": "hero",
  "title": "Sites that load fast",
  "content": "Built to be read.",
  "data": { "image": "/storage/12/office.jpg", "image_alt": "The studio" },
  "order": 0,
  "is_visible": true
}

type is one of hero, text, features, stats, testimonials, team, faq, cta, contact, contact_form, map, or a type declared in the theme.json of the theme that renders the page (see GET /section-types). A theme type's title, content and data are checked against its schema.

GET /pages

Paginated, sorted by order unless told otherwise.

Parameter Meaning
filter[status], filter[template], filter[parent_id], filter[is_homepage] Exact match
filter[title] Partial match
search Partial match on title or slug
sort title, order, created_at, updated_at, published_at; prefix - to reverse
include Any of sections, seo, author, children, parent, media, comma separated
per_page 1 to 100, default 15

GET /pages/tree

Every page nested under its parent through children, ordered by order then title.

GET /pages/homepage

The published homepage with its visible sections, SEO and media.

GET /pages/resolve?path=/services/web-design

Finds a page by its full path, walking the tree one segment at a time. An empty path or / returns the homepage. Use this for nested pages: slugs are only unique among siblings.

GET /pages/{slugOrId}

One page with sections, SEO, author, children and media. A slug that exists under more than one parent matches the first found, so prefer resolve or the id.

POST /pages (token)

Only title is required. 201 on success.

Field Rule
title Required, up to 255
slug Optional; generated from the title when omitted
content, excerpt Optional; excerpt up to 1000
template A built-in layout (default, landing, contact, about, services, blank) or an installed theme
status draft, published or archived
parent_id An existing page id
order Integer, 0 or more
is_homepage, show_in_nav Boolean. Setting a homepage unsets the previous one
nav_label Up to 255
custom_fields Object
published_at Date. A future date schedules the page
sections Array of section objects; type is required on each
seo Object, the same fields as per-page SEO

A top-level slug of admin, api, build, storage or up is refused with a 422, because each is a real directory in the document root.

PUT /pages/{page} (token)

{page} is the id or the slug. Send only what changes.

sections, when present, replaces the page's whole list: a section with an id belonging to this page is updated in place, one without is created, and any stored section missing from the list is deleted along with its media. Leave sections out to keep them untouched.

A change is snapshotted, so the previous state can be restored.

A template change that would leave sections the new theme cannot draw is a 422 on template naming them. Remove or replace them in the same request, or first.

GET /section-types?template= (token)

The section types a page with this template may hold: the built-in ones, then those declared by the theme that renders it (the template's theme, else SITE_THEME). Leave template out for a page with none. An unknown template is a 422.

{
  "data": {
    "theme": "shopfront",
    "types": [
      {
        "type": "hero",
        "source": "base",
        "label": "Hero",
        "blurb": "Large banner with heading and call-to-action.",
        "fields": {
          "title": { "type": "text", "label": "Headline", "inspector": false },
          "data.alignment": { "type": "select", "label": "Alignment", "options": [{ "value": "left", "label": "Left" }, { "value": "center", "label": "Center" }] }
        },
        "defaults": { "title": "Your headline goes here", "content": "…", "data": { "alignment": "center" } }
      }
    ]
  }
}

source is base or theme. fields maps a path (title, content, data.<key>) to its field; ARCHITECTURE.md lists the field types. defaults is what a new section of the type starts with.

GET /pages/{page}/revisions (token)

The 30 most recent earlier states, newest first.

{
  "data": [
    {
      "id": 91,
      "created_at": "2026-11-24T16:40:03+00:00",
      "author": "Editor",
      "snapshot": { "title": "Web design", "sections": [] }
    }
  ]
}

To restore one, PUT its snapshot back to the page.

DELETE /pages/{page} (token)

A soft delete.

Per-page SEO

GET /pages/{page}/seo (token)

PUT /pages/{page}/seo (token)

All fields optional:

meta_title, og_title, twitter_title (up to 255); meta_description, meta_keywords, og_description, twitter_description, og_image, twitter_image (up to 500); og_type, twitter_card (up to 50); canonical_url (a URL); robots (up to 100); schema_markup (object); custom_head (up to 5000).

Search

GET /search?q=design

Published pages whose title, content or excerpt contains q (2 to 200 characters), most recently updated first. limit sets the page size, 1 to 100, default 15. meta echoes the query.

posts lists up to limit published blog posts whose title, excerpt or body contains q, newest first, each with its id, title, slug, path, summary, cover_image, tags (names) and published_at.

Public forms

Both forms are throttled to 5 a minute and share two anti-spam fields:

  • website must be absent or empty. It is a hidden field people never see.
  • form_token should carry a token from GET /form-token, fetched when the form page opens. Submissions without one, or sent within three seconds of it, are treated as automated.

A submission the filter judges to be spam still answers 201 with the usual thank you. It is stored and shown in the dashboard but not emailed.

GET /form-token

Throttled to 30 a minute, never cached.

{ "token": "1795000000.4f2c..." }

POST /enquiries

Field Rule
type Required: contact, or a kind a theme the site uses declares under enquiries in its theme.json
name Required, up to 255
email Required
organisation, phone Optional
message Optional, up to 10000
consent Must be accepted
details Optional object of up to 20 extra answers: short values or flat lists
{
  "message": "Thank you. We have your details and will be in touch shortly.",
  "reference": 57
}

The enquiry is emailed to the enquiry_email_<type> setting, falling back to enquiry_email, then contact_email.

POST /job-applications

Multipart, because of the CV.

Field Rule
job Required: the slug of a published vacancy
name, email Required
phone Optional
cover_letter Required, up to 10000
cv Required file: pdf, doc or docx, up to 5 MB

Answers 201 with a message and a reference. The application is emailed to the vacancy's application_email, falling back to the contact_email setting.

Jobs

All token. Vacancies reach the public through the generated careers pages, not through the API.

GET /jobs

Newest update first. search matches title or location; per_page is 1 to 50, default 10.

GET /jobs/{id}

POST /jobs

PUT /jobs/{id}

Field Rule
title, slug, summary Required. The slug is unique and uses letters, numbers, dashes and underscores
status Required: draft, published or closed
location, job_type, hours, salary, employment_type, description Optional text
responsibilities, essential, desirable, benefits Optional lists of strings
application_email Optional; where applications for this vacancy go
published_at, closes_at Optional dates

Publishing a vacancy with no published_at stamps it with the current time. Create answers 201.

DELETE /jobs/{id}

Answers 204.

Blog

All token. Posts reach the public through the generated blog pages, not through the API.

GET /posts

Newest first, by publish date, or by last edit for drafts. search matches the title or excerpt; status is draft, published or scheduled; tag is a tag's slug; per_page is 1 to 50, default 10.

GET /posts/{id}

POST /posts

PUT /posts/{id}

Field Rule
title Required
slug Optional. Unique, letters, numbers, dashes and underscores, and not page, tag or feed. Left out, a new post gets one made from its title (-2, -3 and so on when taken) and a saved post keeps its own
status Required: draft or published
body Optional HTML. It is cleaned before it is stored: only headings, paragraphs, lists, quotes, code blocks, links, images and inline emphasis survive
excerpt Optional, up to 500 characters. A post published without one gets one written from the opening sentences of its body, headings and code left out
cover_image, cover_image_alt Optional image address and its description
tags Optional list of up to 20 names, each up to 50 characters, no two the same. Sent, it replaces the post's tags (an empty list clears them); left out, they are kept
published_at Optional. A day (2026-12-05): today means now, a later day the start of that day, and a post keeps its exact moment while its day is unchanged. A full date and time is used as it is. One in the future schedules the post
autosave Optional boolean, sent by the editor when a draft saves itself. Such saves keep at most one earlier version every ten minutes
meta_title, meta_description Optional; what search engines are shown

Publishing a post with no published_at stamps it with the current time. A post is on the site once it is published, its date has passed and the site has been built. Create answers 201. The answer includes is_scheduled and the post's public path, and tags as { name, slug } pairs.

DELETE /posts/{id}

Answers 204.

GET /posts/{id}/revisions

Up to the last 30 earlier states of the post, newest first, each taken just before a save changed it: id, created_at, author and the snapshot (title, slug, excerpt, body, cover, tags, status, publish date and search fields). Restoring is done by saving a snapshot's fields back.

POST /posts/preview

The post as the site would show it, as HTML, from the fields sent (those of PUT /posts/{id}, all optional, plus id for a saved post). Nothing is saved. The body is cleaned exactly as it is on save.

GET /post-tags

Every blog tag that is on at least one post, by name, each with its slug and posts_count. A tag is made the first time a post is saved with it.

PUT /post-tags/{slug}

name is required, up to 50 characters. Renames the tag, and its address follows. Given the name of another tag (in any case), the two are merged: the posts move to that tag and this one is deleted. Answers with the tag list.

DELETE /post-tags/{slug}

Answers 204. The tag comes off every post; the posts stay.

Applications and enquiries

All token.

GET /job-applications

GET /enquiries

Newest first; per_page is 1 to 100, default 20. held=1 lists only what the spam filter is holding, and meta.held always carries the held count. Enquiries also filter by type.

Each row includes delivery_status (sent, failed or spam) and, where the filter flagged it, a spam_reason. meta.kinds lists the kinds of enquiry, as GET /enquiry-kinds does.

GET /theme-settings

(token) The settings the site's themes declare in their theme.json, in groups, for the Settings screen. Values are read and saved with the ordinary settings endpoints.

{ "data": [
  { "group": "Footer", "fields": [
    { "key": "footer_notice", "label": "Footer notice", "type": "textarea", "help": null, "placeholder": null }
  ] }
] }

GET /enquiry-kinds

The kinds of enquiry this site takes, for the inbox's tabs and the notification addresses in Settings: contact, then those declared by the themes the site uses, then any older kind that still holds messages.

{ "data": [
  { "value": "contact", "label": "Enquiry", "plural": "Enquiries", "setting": "enquiry_email_contact" },
  { "value": "client_review", "label": "Client review", "plural": "Client reviews", "setting": "enquiry_email_client_review" }
] }

GET /job-applications/{id}/cv

Downloads the CV under its original file name.

POST /enquiries/{id}/release

POST /job-applications/{id}/release

Sends a held submission on to the inbox after all. 422 if it is not being held.

{ "delivery_status": "sent", "message": "Sent to the inbox." }

Settings

All token. A setting is a key, a value and a group.

Endpoint Does
GET /settings Every setting; ?group= narrows it
GET /settings/grouped { group: { key: value } }
GET /settings/{key} One setting
PUT /settings Bulk save: { "settings": { "site_name": "Acme", "contact_email": "hi@acme.test" } }. One transaction; answers the full key and value map
POST /settings Create: key (unique), value, optional group
PUT /settings/{key} Update value and optionally group
DELETE /settings/{key} Answers 204

The dashboard saves through the bulk endpoint.

Media

All token.

GET /media

collection and search (on name) filter; per_page is 1 to 100, default 15.

{
  "id": 12,
  "name": "office",
  "file_name": "office.jpg",
  "mime_type": "image/jpeg",
  "size": 482113,
  "custom_properties": { "alt_text": "The studio", "caption": null },
  "url": "https://example.com/storage/12/office.jpg",
  "collection_name": "library"
}

GET /media/{id}

POST /media

Multipart.

Field Rule
file Required: jpg, jpeg, png, gif, pdf, doc or docx, up to 10 MB
model_type Optional: Page or PageSection
model_id Required with model_type
collection Optional
alt_text, caption Optional

With a model, the file attaches to that page or section. Without one, it goes to the site-wide library, which is what the Media screen uses. Answers 201.

DELETE /media/{id}

Answers 204.

Publishing

GET /site/status (token)

{
  "data": {
    "last_published_at": "2026-11-24T16:41:10+00:00",
    "pending_changes": 3,
    "has_output": true
  }
}

POST /site/publish (token)

Rebuilds the static site and waits for it. Throttled to 10 a minute.

{
  "data": {
    "pages": 9,
    "files": 14,
    "pruned": 1,
    "last_published_at": "2026-11-24T16:41:10+00:00"
  },
  "message": "Site published."
}

409 if a build is already running, 500 with the reason if the build fails. A failed build leaves the live site as it was.

Health

GET /health answers {"status": "ok", "version": "1.0.0"}. Laravel's own check is at /up, outside /api/v1.

Users and roles

Role Permissions
admin all of them
editor edit pages, edit blog, manage jobs, read inbox, manage media, publish site
author edit pages, edit blog, manage media
viewer none

Without publish site, a new page or post may only be a draft, and an existing one keeps its status (422 on status otherwise).

The overall admin (TUXCMS_OWNER_EMAIL) passes every check, and its role cannot be changed nor the account removed.

GET /users (manage users)

Everyone who can sign in, with roles (each with its description and permissions) and permissions (each with its description).

POST /users (manage users)

{ "name": "Ada Okafor", "email": "ada@example.com", "password": "a-long-password", "role": "author" }

201 with the new account. Pass the starting password on to them.

PUT /users/{id} (manage users)

{ "role": "editor" } and/or { "name": "…" }. 422 on role when it is the overall admin, your own account, or the last admin.

DELETE /users/{id} (manage users)

Removes the account and signs it out. 422 on user when it is the overall admin, your own account, or the last admin.

Control panel

See ARCHITECTURE.md, "The control panel".

On every site, signed by the panel

Each request carries X-Tux-Timestamp (Unix seconds), X-Tux-Nonce (random, used once) and X-Tux-Signature: hex(hmac_sha256(TUXCMS_FLEET_KEY, timestamp + "\n" + nonce + "\n" + METHOD + "\n" + path + "\n" + sha256(body))). Here path is below the site root with no leading slash, such as api/v1/fleet/status. An unsigned, wrong, stale (over five minutes) or repeated request gets 404, as does every request to a site with no key.

GET /fleet/status

{ "data": { "name": "Crystal", "url": "https://crystal.example", "release": "1322dda0 2026-11-29",
  "php": "8.3.14", "laravel": "12.0.0", "theme": "crystal", "last_published_at": "2026-11-29T10:00:00+00:00",
  "unpublished_changes": false, "pages": 12, "posts": 4, "people": 3, "enquiries_this_month": 9,
  "owner": "admin@codurou.com", "owner_signed_up": true, "checked_at": "2026-11-29T10:05:00+00:00" } }

POST /fleet/entry

{ "data": { "url": "https://crystal.example/admin/enter#code=…", "created_owner": false } }. The code works once, for a minute. 409 when the site has no overall admin set.

POST /auth/enter

{ "code": "…" } from an entry link. It returns the same response as /auth/login, or 401 once the code is spent or has expired. It is limited to ten requests a minute.

On the panel, for its overall admin (token)

These routes exist only where TUXCMS_FLEET_PANEL=true; elsewhere they return 404. Any account other than the overall admin gets 403.

Method Path
GET /deployments Every site, and panel.release
POST /deployments { "name", "url", "key" }; 422 on url if the site cannot be reached or turns the key away
PUT /deployments/{id} Any of the same; an empty key keeps the current one
DELETE /deployments/{id} Forgets the site; the site itself is untouched
POST /deployments/{id}/check Asks the site again and keeps the answer, or the error
POST /deployments/check Checks every site
POST /deployments/{id}/enter { "data": { "url", "created_owner" } }; 502 when the site does not answer

A deployment comes back as { id, name, url, status, same_release, error, checked_at }. status is the site's last good answer and error the latest failure. The key is never returned.