Skip to content

CLI

The Alokai CMS CLI (alokai-content) lets you import and export content models and pages programmatically. Useful for seeding environments, migrating content, and version-controlling your content schema.

Running the CLI

From the apps/alokon directory:

Terminal window
yarn cli --help

Or after building:

Terminal window
node dist/cli/index.mjs --help

Authentication

All CLI commands require an API key. Create one in Settings → API Keys with the appropriate permissions.

Commands

import

Import content models or pages from a JSON file or directory. When given a directory, files are processed in alphabetical order — name them with a numeric prefix (e.g. 01-hero.json, 02-page.json) to control import order.

Terminal window
yarn cli import \
--api-key=default_sk_... \
--space-id=default \
--environment-id=main \
--schema-path=./schema.json

Options:

OptionRequiredDefaultDescription
--api-keyYesYour Alokai CMS API key
--space-idYesTarget space ID
--environment-idYesTarget environment ID
--schema-pathYesPath to a JSON file or directory of JSON files
--org-idYesOrganization ID
--base-urlNohttp://localhost:8787Alokai CMS base URL

export

Export all content models and pages from a space and environment to a directory. Output is split into content-models/ and content/ subdirectories.

Terminal window
yarn cli export \
--api-key=default_sk_... \
--space-id=default \
--environment-id=main \
--output=./export

Options:

OptionRequiredDefaultDescription
--api-keyYesYour Alokai CMS API key
--space-idYesSource space ID
--environment-idYesSource environment ID
--outputYesOutput directory path
--org-idYesOrganization ID
--base-urlNohttp://localhost:8787Alokai CMS base URL
--include-built-inNofalseInclude built-in models in export

Migrating content between instances

To copy all schemas and content from one Alokai CMS instance (e.g. local) to another (e.g. production), use the export and import commands together.

Step 1: Export from the source instance

Terminal window
yarn cli export \
--api-key=<source-api-key> \
--org-id=<source-org-id> \
--space-id=<source-space-id> \
--environment-id=<source-environment-id> \
--base-url=http://localhost:8787 \
--output=./export \
--include-built-in

This creates ./export/content-models/ and ./export/content/ with all your data.

Step 2: Import content models to the target instance

Terminal window
yarn cli import \
--api-key=<target-api-key> \
--org-id=<target-org-id> \
--space-id=<target-space-id> \
--environment-id=<target-environment-id> \
--base-url=https://<target-cms-url> \
--schema-path=./export/content-models

Step 3: Import content entries to the target instance

Terminal window
yarn cli import \
--api-key=<target-api-key> \
--org-id=<target-org-id> \
--space-id=<target-space-id> \
--environment-id=<target-environment-id> \
--base-url=https://<target-cms-url> \
--schema-path=./export/content

File formats

Content model

{
"type": "content-model",
"name": "Featured Collection",
"api_id": "FeaturedCollection",
"description": "A curated set of products",
"fields": [
{ "name": "title", "type": "text", "label": "Title" },
{ "name": "items", "type": "components", "label": "Items" }
]
}

Page / content entry

{
"type": "content",
"content_type": "page",
"path": "/about",
"locale": "en-US",
"data": {
"componentsAboveFold": [],
"componentsBelowFold": []
}
}