exportSnapshot
The exportSnapshot function fetches a project’s content snapshot from the export endpoint and resolves with the parsed ContentSnapshot. It validates the snapshot’s shape and schema version, and — when you pass a snapshotPath — also writes the snapshot JSON to that path.
Unlike most of the library, exportSnapshot is a package-level function (like createClient), not a method on the ApiClient. You import it directly from @content-island/api-client.
It is the same function the CLI (npx content-island export) is built on, so reach for it directly from a Node script when you need more control than the CLI offers — for example, post-processing the snapshot before writing it.
Example:
import { exportSnapshot } from '@content-island/api-client';
const snapshot = await exportSnapshot({ accessToken: process.env.CONTENT_ISLAND_ACCESS_TOKEN!, snapshotPath: './content-island-snapshot.json',});
console.log(snapshot.meta.exportedAt, snapshot.contents.length);Interface
The exportSnapshot function accepts an options object and returns a promise that resolves with the parsed ContentSnapshot.
import { exportSnapshot } from '@content-island/api-client';
function exportSnapshot(options: ExportSnapshotOptions): Promise<ContentSnapshot>;When you provide a snapshotPath, the file is written atomically — first to a temporary file, then renamed into place — so a failed export never leaves a half-written or corrupt snapshot on disk: you either get the complete file or the previous one untouched. Omit snapshotPath to just get the parsed object back without touching the filesystem.
The exported view is token-driven: a PREVIEW_-prefixed access token exports the preview view, otherwise the published view. See Preview mode for what preview tokens are and how they work.
Parameters
The exportSnapshot function accepts a single ExportSnapshotOptions object:
interface ExportSnapshotOptions { accessToken: string; snapshotPath?: string; domain?: string; secureProtocol?: boolean; apiVersion?: string;}| Parameter | Type | Required | Description |
|---|---|---|---|
accessToken | string | Yes | Identifies the project to export. A PREVIEW_-prefixed token exports the preview view; otherwise the published view. |
snapshotPath | string | No | When given, writes the snapshot JSON to this path. Omit it to just receive the parsed object. |
domain | string | No | Override the API domain. |
secureProtocol | boolean | No | Whether to use HTTPS. |
apiVersion | string | No | Override the API version. |
Output
The exportSnapshot function resolves with the parsed ContentSnapshot, which has the following structure:
interface ContentSnapshot { meta: SnapshotMeta; // { schemaVersion, exportedAt, projectId, view } project: Project; contents: Content[];}If the export endpoint returns a non-2xx response, the call rejects with the standard wire-contract ApiClientError. In particular, a 429 response — the export endpoint’s per-project rate limit — surfaces as an ApiClientError with code RATE_LIMITED.