# Publish site content

URL: https://docs.spacerun.co/docs/platform/guides/site-publishing

> Save drafts, publish settings and page versions, configure visibility, and recover with rollback.

Prerequisites: the matching site/content permissions and [apiRequest](https://docs.spacerun.co/docs/platform/guides/quickstart). Settings writes accept one of `site.write`, `billing.write`, or `settings.write`; page editing/publishing has its own permissions in the reference.

## Draft and publish settings

Read the current section before replacing its draft. [saveSiteSettingsDraft](https://docs.spacerun.co/docs/platform/reference/site-settings/saveSiteSettingsDraft) stores an object without publishing it; [publishSiteSettingsSection](https://docs.spacerun.co/docs/platform/reference/site-settings/publishSiteSettingsSection) publishes it and returns the new version.

```ts
await apiRequest("/v1/admin/site/settings/branding", {
  method: "PUT", body: JSON.stringify({ draft: brandingDraft }),
});
const published = await apiRequest("/v1/admin/site/settings/branding/publish", {
  method: "POST", body: JSON.stringify({ note: "Reviewed branding update" }),
});
console.log(published.version);
```

`brandingDraft` is the complete deployment-specific section object read/edited by your application. The current section schema is permissive; it does not prove arbitrary keys will affect the UI. Inspect existing settings and consumers rather than inventing a new section format.

## Create and publish a page version

```ts
const page = await apiRequest("/v1/admin/site/pages", {
  method: "PUT", body: JSON.stringify({ slug: "getting-started", title: "Getting started", kind: "page" }),
});
const version = await apiRequest(`/v1/admin/site/pages/${page.id}/versions`, {
  method: "POST", body: JSON.stringify({ markdown: "# Getting started\n\nWelcome." }),
});
await apiRequest(`/v1/admin/site/pages/${page.id}/publish`, {
  method: "POST", body: JSON.stringify({ version: Number(version.version) }),
});
```

The sequence is [upsertSitePage](https://docs.spacerun.co/docs/platform/reference/site-pages/upsertSitePage), [saveSitePageVersion](https://docs.spacerun.co/docs/platform/reference/site-pages/saveSitePageVersion), then [publishSitePageVersion](https://docs.spacerun.co/docs/platform/reference/site-pages/publishSitePageVersion). Creating metadata or saving a version alone does not publish it.

## Visibility and rollback

Navigation/content blocks choose `landing` or `portal`; announcements also have surfaces, audience and start/end times. Use the appropriate status transition instead of assuming a saved draft is public. [getPublicSite](https://docs.spacerun.co/docs/platform/reference/public-site/getPublicSite) returns only the anonymous published subset, including resolved feature flags rather than private rollout/audience rules. Its `surface` filter narrows blocks/navigation.

Inspect [listSiteSettingsVersions](https://docs.spacerun.co/docs/platform/reference/site-settings/listSiteSettingsVersions) and use [rollbackSiteSettingsSection](https://docs.spacerun.co/docs/platform/reference/site-settings/rollbackSiteSettingsSection) with a known version when recovering settings. Page publishing can select an earlier stored version. A 204 means no body; permission failures need the operation-specific key, and invalid section/slug/version values return validation errors. Keep legal reacceptance behavior explicit when changing legal content.
