Content API reference

The content API is the read surface of a site: a front end asks it for published content and renders the answer itself. It needs no credential — a request is answered for the site its host resolves to, and nothing else.

Property Value
Base URL The site's own host. Every path below is relative to it
Authentication None. A host that resolves to no site answers 404, never a guess
Content type application/json, except the binary and crawler surfaces noted below
Cross-origin Every response carries Access-Control-Allow-Origin: *
Caching Most routes are served from a per-site cache for 10 seconds (snolla.cacheTimeout, in milliseconds)

Two route families and two shapes of answer:

An identifier in a path is the row's identifier, not its alias or slug. Where a route is addressed by a slug — tables, table records — the path parameter says so.

Pages

Route Answers
GET /pages A listing of pages: filter, sort, page, hitsPerPage and facets are the language of Selecting content, and path and template narrow that same listing
POST /pages/query The same listing with the same keys as a JSON body — one validator, so a condition cannot mean two things depending on how it arrived
GET /pages/viewModel?path= One page by its path, as a resolved view model
GET /pages/filters The panel available to a listing: { "facets": [...] }

A listing is asked for with its keys; an empty answer is still an answer. A view model, on the other hand, is one page or nothing: a path that matches no page is 404, and a listing that asks for a field path the surface does not declare is 400 with the refusal body below.

curl "$CONTENT_API/pages/viewModel?path=/about"

A listing that matched nothing — 200, an empty page of rows and the count it found:

curl "$CONTENT_API/pages?hitsPerPage=24"
{ "pages": [], "limit": 24, "offset": 0, "total": 0 }

Blogs, catalogs and stores

The three families share one tree: a container, its categories and tags (and, for a store, its vendors), the content under each, and a viewModel route wherever a single object is what a front end wants. blogId, catalogId and storeId are identifiers; the containers' own routes take path.

Node Blogs Catalogs Stores
Container by path GET /blogs/viewModel?path= GET /catalogs/viewModel?path= GET /stores/viewModel?path=
Container by id GET /blogs/:blogId GET /catalogs/:catalogId GET /stores/:storeId
Categories GET /blogs/:blogId/categories GET /catalogs/:catalogId/categories GET /stores/:storeId/categories
One category GET /blogs/:blogId/categories/viewModel?path= GET /catalogs/:catalogId/categories/viewModel?path= GET /stores/:storeId/categories/viewModel?path=
Content of a category GET /blogs/:blogId/categories/:categoryId/posts GET /catalogs/:catalogId/categories/:categoryId/products GET /stores/:storeId/categories/:categoryId/products
Tags GET /blogs/:blogId/tags GET /catalogs/:catalogId/tags GET /stores/:storeId/tags
One tag GET /blogs/:blogId/tags/viewModel?path= GET /catalogs/:catalogId/tags/viewModel?path= GET /stores/:storeId/tags/viewModel?path=
Content of a tag GET /blogs/:blogId/tags/:tagId/posts GET /catalogs/:catalogId/tags/:tagId/products GET /stores/:storeId/tags/:tagId/products
Vendors — — GET /stores/:storeId/vendors
One vendor — — GET /stores/:storeId/vendors/viewModel?path=
Content of a vendor — — GET /stores/:storeId/vendors/:vendorId/products
The listing of the container GET /blogs/:blogId/posts GET /catalogs/:catalogId/products GET /stores/:storeId/products

The content listings — posts, products — are listings in the shape above, with a posts or products array, limit/offset/total, and a default window of 10. The content-api's own twins for those, when a front end wants one call instead of a page of rows:

Twin Answers
GET /blogs/:blogId/posts/viewModel?path= One post
GET /catalogs/:catalogId/products/viewModel?path= One product
GET /stores/:storeId/products/viewModel?path= One product, with its variants
curl "$CONTENT_API/stores/<store-id>/products?limit=12&offset=24"

Tables

A table is a container of records that is not a page: it has no URL of its own on the site.

Route Answers
GET /tables/:tableSlug The table: id, title, slug and its template (id, name, alias, description)
GET /tables/:tableSlug/records Every published record of the table, as a plain array — no window
GET /tables/:tableSlug/records/:recordSlug One record, as a resolved view model

Static pages

GET /static-pages?path=<path> answers one rendered static page — path, content, contentType and encoding. A path that matches nothing is 404.

Reviews

GET /reviews is a listing of approved reviews: path narrows to the content they attach to, template to one template, and limit (default 20) with offset is the window.

Search

Route Answers
POST /api/search A text search over the site's index, with the site's facet definitions alongside the result
GET /search/suggest?q= Up to ten { id, title, path } entries for a search box

The request body of POST /api/search, the way the index is built and what a facet definition holds are the subject of Indexing and search.

Files and media

Route Answers
GET /assets/:ownerId Anything below that folder owner: a content file as uploaded, or a picture at a size the active theme declares
GET /galleries/:galleryId/images/:imageSize/:filename One gallery picture at a theme size

Both are covered in Files, images and themes, with the way a theme declares sizes.

Crawler surfaces

Route Answers
GET /sitemap.xml The sitemap index
GET /sitemap-<source>-<page>.xml One chunk of the sitemap
GET /robots.txt The site's robots.txt, as text/plain
GET /redirections The site's redirect rows as JSON, in Seq order

All four are described in Domains, redirects and crawler files. The redirections route exists for a front end that renders content as a consumer of this API: it has no database of its own, and its redirects are part of the behaviour it must reproduce.

The site

GET / answers the site's own row — its title, alias, primary domain, active theme and settings — which a front end uses to fill a layout or to check which site it is talking to.

Refusals

Status When
200 The answer, including an empty listing
400 A listing asked for a filter or sort path the surface does not declare, for a template it cannot list, or for a window that cannot be expressed in whole pages
404 The host resolves to no site, the site has no active theme, a view model, table or record matches nothing, or the request is not a listing at all

A refusal names the code and the offending path; a declaration-named refusal also names which paths the surface does declare, so a client can correct itself without reading this page again:

{
  "error": {
    "code": "filter-path-not-declared",
    "path": "price_from",
    "declared": ["categories", "path", "published", "template", "title"]
  }
}

The two declaration refusals are filter-path-not-declared and sort-path-not-declared; a window that cannot be expressed in whole pages answers { "error": { "code": "window-invalid", "path": "offset" } } and an unlistable template { "error": { "code": "template-unsupported", "path": "template" } } — neither carries a declared list, which is what tells the three apart. The list under declared is the surface's own, read from the site's templates, so it grows as templates do.

Related