Skip to main content

In your app

A function makes the call on the client it is given, so your code passes the real one and a test passes a fake.

Add the function

src/attract/unpublish-page.ts

Call it

A script makes the client once and calls the function:
scripts/unpublish-page.ts
Terminal
A route handler, a job or a queue worker calls it the same way.
Answers the draft. Not for singleton types (the site’s global content).

Find the id

id is the document’s _id, from a list. Ask the list for only the fields you need: each row is a document’s id and those fields.
TypeScript
Pass row.id as id. Drafts: list with { aposMode: 'draft' } to get the draft’s id (Find an id).

Required parameters

One object, e.g. unpublishPage({ id }); leave out the optional fields.
string
required
Required. Computed document ID (can optionally include mode and locale, e.g., id:en:published) Matches ^\S+$.
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 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). Read its properties (page.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
Always sent. Unique document identifier, may include mode and locale (e.g., “id:en:published”)
string
Always sent. Base document ID without mode/locale qualifiers.
string
Always sent. Document locale code.
Date
Always sent. Page last update timestamp. Format: an ISO 8601 date and time.
string
Always sent. URL slug for the page.
string
Always sent. Full hierarchical path in the page tree.
number
Always sent. Depth level in the page tree (0 = root level)
FlatPageResponseResultsItemVisibility
Always sent. Page visibility setting. One of public, loginRequired, private; a newer site may send others, so keep a fallback.
string
Always sent. Page type module name.
string
Always sent. Page title. At most 100 characters.
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.
string | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Sortable version of the page title.
number | null
Sometimes sent: undefined when the site leaves it out, and it can be null. Sort order within parent page.
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.
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<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; catch only what you want to react to (see Errors and testing).
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: a write may have landed. Read: siteMessage, errorName, data.
no answer
No answer: DNS, a refused connection, TLS, or the timeout (15 s per attempt by default).Retried first: Only when nothing reached the site (neverConnected()); never after a timeout, when it may have landed. 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 your sites (createSiteClients()) don’t have.Retried first: No: nothing was sent. Read: message, slug.
setup
The client’s settings are wrong: no FETCHSKI_ATTRACT_URL (or baseUrl), or a malformed API key.Retried first: No: nothing was sent. Read: message (what to fix).

Behavior

  • Access: an API key with content:pages:publish (or a master above it: content:pages:all, content:all, admin:all). A signed-in person may call it as far as their own permissions allow; anyone else gets 403.
  • Rate limit: the key’s own writes-per-minute limit, set when the key is created (default 120); over it, 429 with Retry-After. The client waits and retries for you; you see RateLimited only if that runs out.
  • Retries: a write is sent again only after a 429 (refused before it acted) or when it never reached the site. After a timeout or a 5xx it may have landed: check before you send it again.
  • Timeout: 15 s per attempt by default; raise timeout (milliseconds) on the client for longer.

Test it

It calls the function above with a fake client: the fake answers every call with a valid example, so nothing leaves your machine and no settings or key are needed. Run it with node --test.
tests/pages-unpublishPage.test.ts
Answer with your own values: fake pages.unpublishPage with factories.Page({...}), the fields you give over a valid example.
tests/pages-unpublishPage-answer.test.ts

List pages

site.pages().listPages()

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()

POST /@apostrophecms/page/{_id}/unpublish

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