Skip to main content

In your app

A controller answers a route on your app: it calls listPages() and returns the answer.

Add the controller

app/controllers/list_pages_controller.ts

Add the route

start/routes.ts

Call it

Terminal
With node ace serve running, it prints its answer as JSON.
With all=1&flat=1, every page in one flat list (results) instead, for building navigation or a static site. Page types’ own fields come with each page.
One object, e.g. listPages({ all }); leave out the optional fields.
number | null | undefined
Optional. Leave it out and the site uses 0. 1: every page the caller may see, orphan and archived pages included. flat=1 needs it. One of 0, 1.
number | null | undefined
Optional. Leave it out and the site uses 0. 1, with all=1: every page in one flat list (results), each naming its children by _id. Without all=1 the tree comes back as if it were 0. One of 0, 1.
boolean | null | undefined
Optional. Leave it out and the site uses true. false: leave each page’s _children out. Default true.
AposMode | null | undefined
Optional. Leave it out and the site uses "published". published (the default) or draft. Drafts need a credential that may see them: an API key with the type’s write scope (content:<type>:write), or a signed-in editor. The public and a key with only the read scope get 403. One of draft, published.
string | null | undefined
Optional. Leave it out (or pass null) and it isn’t sent: the site’s default applies. The locale to read or write, e.g. en (default: the site’s default locale).
A ListPagesResponse. The page tree: the home page (every field of Page), its children nested in _children. With all=1&flat=1, results instead: every page in one flat list, and none of the home page’s fields. Read its properties (listPages.id): each says whether the site always sends it. The example answer is the site’s wire JSON: some keys differ from the property names (_id → id, _ancestors → ancestors, _children → children …).
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Unique document identifier, may include mode and locale (e.g., “id:en:published”)
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Base document ID without mode/locale qualifiers.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Document locale code.
AposMode | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Document mode (draft or published) One of draft, published; a newer site may send others, so keep a fallback.
boolean | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Whether the page is archived.
Date | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Page creation timestamp. Format: an ISO 8601 date and time.
Date | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Page last update timestamp. Format: an ISO 8601 date and time.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Sortable version of the page title.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. URL slug for the page.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Full hierarchical path in the page tree.
number | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Sort order within parent page.
number | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Depth level in the page tree (0 = root level)
boolean | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Whether page is orphaned (not in tree structure)
readonly string[] | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Array of parking lot configurations if page is parked.
FlatPageResponseResultsItemVisibility | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Page visibility setting. One of public, loginRequired, private; a newer site may send others, so keep a fallback.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Page type module name.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Page title. At most 100 characters.
MainArea
Sometimes sent: undefined when the site leaves it out. A MainArea. Widgets, top to bottom: send { "items": [ … ] }, one object per widget with its type. Writing it replaces the whole area.
readonly Page[] | null
Sometimes sent: undefined when the site leaves it out, and it can be null. A list of Page. The page’s ancestors, from the home page down (each without its own _ancestors and _children).
readonly Page[] | null
Sometimes sent: undefined when the site leaves it out, and it can be null. A list of Page. Its child pages, each with its own _children where the request asked for more levels. Its fields are listed under the first Page above.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Full URL to the page. Format: an absolute URL.
boolean | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Whether current user can edit this page.
boolean | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Whether current user can publish this page.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. The _id of the piece/page that was copied to create this document (only present if created via _copyingId)
Page
Sometimes sent: undefined when the site leaves it out. A Page. A page: the fields every page has, and each page type’s own (type says which page type it is; a field belongs only to the page types that define it). Its fields are listed under the first Page above.
Page
Sometimes sent: undefined when the site leaves it out. A Page. A page: the fields every page has, and each page type’s own (type says which page type it is; a field belongs only to the page types that define it). Its fields are listed under the first Page above.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. The draft’s preview share key, while its share link is on: the link is the draft’s _url with aposShareKey and aposShareId (the draft’s _id) in its query. Absent otherwise, and on published documents.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. An ISO 8601 date and time, e.g. 2026-10-21T14:30:00.000Z.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. An ISO 8601 date and time, e.g. 2026-10-21T14:30:00.000Z.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Overrides the document title in the browser tab and search results. Leave blank to use the regular title.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Shown in search results and link previews. Aim for 150–160 characters.
ImageArea
Sometimes sent: undefined when the site leaves it out. An ImageArea. Used for Open Graph / social link previews. Recommended 1200×630. Widgets, top to bottom: send { "items": [ … ] }, one object per widget with its type. Writing it replaces the whole area. Its fields are listed under the first ImageArea above.
readonly PagePageFontOverridesItem[] | null
Sometimes sent: undefined when the site leaves it out, and it can be null. A list of PagePageFontOverridesItem. Optional. Set part of this page in a different typeface. Leave empty to follow the site’s fonts (Site design → Typography). Individual sections can still override this for themselves. At most 4 items. Its fields are listed under the first PagePageFontOverridesItem above.
Sometimes sent: undefined when the site leaves it out, and it can be null. The ribbon of phrases scrolling across the top of the footer. Its phrases and the site-wide default are set in Site design → Footer: Marquee. One of inherit, on, off; a newer site may send others, so keep a fallback.
SectionsArea
Sometimes sent: undefined when the site leaves it out. A SectionsArea. Widgets, top to bottom: send { "items": [ … ] }, one object per widget with its type. Writing it replaces the whole area. A new document starts with page-header. Its fields are listed under the first SectionsArea above.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Any Font Awesome icon name, e.g. star, bolt, arrow-left-to-bracket (no “fa-” prefix). Browse at fontawesome.com/icons.
ComingSoonIconFamily | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Icon family. One of classic-regular, duotone-regular, brands, jelly, jelly-duo, whiteboard; a newer site may send others, so keep a fallback.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional — leave empty to use the design’s own color rhythm.
ComingSoonIconAnimation | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Icon animation. One of none, fa-beat, fa-bounce, fa-fade, fa-beat-fade, fa-flip, fa-shake, fa-spin; a newer site may send others, so keep a fallback.
ComingSoonIconSize | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Relative to the component’s base icon size. One of default, sm, lg, xl, 2xl, 2x, 3x, 4x, 5x; a newer site may send others, so keep a fallback.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional. Shown under the icon while this page has no content. Leave empty for a tasteful default line.
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional. Color of the ”← back” link at the top of every post. Leave empty to use the site accent color.
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional light-theme override. Falls back to the dark-theme color, then the accent.
Sometimes sent: undefined when the site leaves it out, and it can be null. Back link weight. One of normal, medium, semibold, bold, extrabold; a newer site may send others, so keep a fallback.
Sometimes sent: undefined when the site leaves it out, and it can be null. Back link size. One of small, normal, large, xlarge; a newer site may send others, so keep a fallback.
SectionsArea
Sometimes sent: undefined when the site leaves it out. A SectionsArea. Widgets, top to bottom: send { "items": [ … ] }, one object per widget with its type. Writing it replaces the whole area. A new document starts with page-header. Its fields are listed under the first SectionsArea above.
BlogListArea
Sometimes sent: undefined when the site leaves it out. A BlogListArea. Widgets, top to bottom: send { "items": [ … ] }, one object per widget with its type. Writing it replaces the whole area. A new document starts with blog-list. Its fields are listed under the first BlogListArea above.
SectionsArea
Sometimes sent: undefined when the site leaves it out. A SectionsArea. Widgets, top to bottom: send { "items": [ … ] }, one object per widget with its type. Writing it replaces the whole area. Its fields are listed under the first SectionsArea above.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. The visible button text. Leave empty to hide the button.
BackButtonVariant | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Solid fills with the color; Outline / Soft / Text link use it for the border + text. One of solid, outline, soft, link; a newer site may send others, so keep a fallback.
BackButtonSize | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Button size. One of small, normal, large; a newer site may send others, so keep a fallback.
BackButtonRadius | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Corner radius. One of pill, rounded, slight, square; a newer site may send others, so keep a fallback.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Solid fill, or the border + text for the other styles. Defaults to the brand accent; CLEAR it for a transparent, outline-only button.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional light-theme override. Falls back to the dark-theme color. (Brand tokens already flip per theme.)
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. The text/icon color. Clear it to derive from the button color (readable on solid fills).
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional light-theme override. Falls back to the dark-theme label color.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional. Drives the hover treatment. Leave empty to derive it from the button color.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional light-theme override. Falls back to the dark-theme hover color.
BackButtonStyle | null
Sometimes sent: undefined when the site leaves it out, and it can be null. The hover treatment: a soft shadow, a colored offset shadow, a glow, a fill sweep, or a thicker border. One of none, single, dual, glow, sweep, thicken; a newer site may send others, so keep a fallback.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional. The offset-shadow or glow color on hover. Leave empty to use the site secondary color.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional light-theme override. Falls back to the dark-theme shadow color.
BackButtonAnimation | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Hover motion. One of lift, scale, lift-scale, none; a newer site may send others, so keep a fallback.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Any Font Awesome icon name, e.g. star, bolt, arrow-left-to-bracket (no “fa-” prefix). Browse at fontawesome.com/icons.
BackButtonIconFamily | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Icon family. One of classic-regular, duotone-regular, brands, jelly, jelly-duo, whiteboard; a newer site may send others, so keep a fallback.
BackButtonIconPosition | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Which side of the label the icon sits on (when an icon name is set). One of before, after; a newer site may send others, so keep a fallback.
boolean | null
Sometimes sent: undefined when the site leaves it out, and it can be null. The icon slides toward its side on hover (e.g. an arrow edges outward).
readonly PagePostFontOverridesItem[] | null
Sometimes sent: undefined when the site leaves it out, and it can be null. A list of PagePostFontOverridesItem. Optional. Set part of every post in a different typeface. Leave empty to follow the site’s fonts (Site design → Typography). An individual post can replace this on its own Fonts tab. At most 4 items. Its fields are listed under the first PagePostFontOverridesItem above.
PostTextSize | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Body text size. One of small, normal, large, xlarge; a newer site may send others, so keep a fallback.
PostTextWeight | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Body text weight. One of normal, medium, semibold; a newer site may send others, so keep a fallback.
PostContentWidth | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Reading measure — how wide the article column gets. Posts that contain section widgets open to Full width automatically so the widgets have room. One of narrow, normal, wide, xwide, full; a newer site may send others, so keep a fallback.
PostLineHeight | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Line height. One of tight, normal, relaxed; a newer site may send others, so keep a fallback.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Links, the blockquote rule, and heading accents. Leave empty to use the site link color.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional light-theme override. Falls back to the dark-theme color, then the link color.
PostHeadingWeight | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Heading weight. One of normal, medium, semibold, bold, extrabold; a newer site may send others, so keep a fallback.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional. Overrides in-article heading color. Leave empty to track the theme’s text color.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Optional light-theme override. Falls back to the dark-theme color, then the theme default.
PostCustomCSS | null
Sometimes sent: undefined when the site leaves it out, and it can be null. A PostCustomCSS. CSS for every blog post’s page: the title band, the article and its parts. It wins over Site design → Custom CSS → Blog post. Its fields are listed under the first PostCustomCSS above.
readonly FlatPageResponseResultsItem[] | null
Sometimes sent: undefined when the site leaves it out, and it can be null. A list of FlatPageResponseResultsItem. With all=1&flat=1: every page, in tree order.
Readonly<Record<string, unknown>>
Always there: {} when there are none. Any keys the site sent that aren’t listed above (such as one added after this SDK was built), by their wire names, as sent. Pass this model to a write and they are sent too.
Nothing to catch: the SDK retries what is safe, and throws the rest as the classes below. Your exception handler turns them into your app’s own answers, once for every call (see Map SDK errors to responses); catch only what you want to react to here.
400
The site refused what was sent: errors lists each field’s problem, siteMessage the first.Retried first: No. Read: errors (field → messages), siteMessage.
401
The API key is missing or refused (malformed, revoked, expired), or a signature its signing mode needs is missing or stale.Retried first: No. Read: siteMessage, errorName, data.
403
The key may not do this: a scope it lacks, or an address outside its allowlist. siteMessage names it.Retried first: No. Read: siteMessage, errorName, data.
404
Nothing matches, or the caller may not see it.Retried first: No. Read: siteMessage, errorName, data.
500
The site failed. Its logs say why.Retried first: No (only a 502, 503 or 504 is retried). Read: siteMessage, errorName, data.
no answer
No answer: DNS, a refused connection, TLS, or the timeout (15 s per attempt by default).Retried first: Yes, after 0.5 s then 1 s. Read: reason, neverConnected.
not sent
The client refused to send it (e.g. a path segment of ..); the site never saw it.Retried first: No. Read: reason (what to change).
any other
Any other status, or a success whose JSON doesn’t match this SDK version’s types (update the SDK).Retried first: No. Read: reason, status.
setup
sites.forSite('acme') named a slug config/attract.ts doesn’t list (with the keys in the database: no row in attract_api_keys).Retried first: No: nothing was sent. Read: message, slug.
setup
The site’s entry is wrong: a malformed baseUrl or key, a key filed under another slug, or no default site. node ace attract:check names the fix.Retried first: No: nothing was sent. Read: message (what to fix).

Behavior

  • Access: an API key with content:pages:read (or a master above it: content:pages:all, content:all, admin:all) reads the published documents; drafts (aposMode=draft) need content:pages:write (or a master above it). A signed-in person may call it as far as their own permissions allow; anyone else gets 404.
  • Rate limit: the key’s own reads-per-minute limit, set when the key is created (default 600); over it, 429 with Retry-After. The client waits and retries for you; you see RateLimited only if that runs out.
  • Retries: a read is safe to repeat: the client retries it on no answer, a 502/503/504 and a 429.
  • Timeout: 15 s per attempt by default; raise timeout (milliseconds) in config/attract.ts for longer.

More examples

listPagesPick() takes aposMode and aposLocale, after the fields to answer: each row is the document’s id and those fields.

Test it

It calls the controller above with the SDK faked: fakeAttract() puts the fake in the container for this one test, and it answers every call with a valid example, so nothing leaves your machine and no key is read. Save it as tests/unit/pages_list_pages.spec.ts, then run your tests:
tests/unit/pages_list_pages.spec.ts
Terminal

Create a page

site.pages().createPage()

Archive pages

site.pages().archivePages()

Copy pages to another locale

site.pages().localizePages()

Publish pages

site.pages().publishPages()

Restore pages

site.pages().restorePages()

Get a page

site.pages().getPage()

GET /@apostrophecms/page

The endpoint this calls, in the API reference: the HTTP request and answer, and every rule the site checks.