Skip to Content
Docs

Sites CLI Reference

Initialize Site source code and manage Site, Auth Profile, and Site User records with the Contextual CLI.

This documentation assumes you are running Contextual CLI 0.17.0 or later. Check your version with ctxl --version and follow CLI installation and tenant sign-in.

Replace my-config with the CLI configuration ID for the intended tenant. The examples use Site ID customer-portal and Auth Profile ID customer-portal-auth; substitute your own IDs when working with existing resources. Confirm the tenant with ctxl config get my-config --json before writing.

Understand the Sites Resource Model

Resource CLI Type ID Relationships
Site site Holds application identity and optional authProfileId and testAuthProfileId references.
Auth Profile auth-profile Selects the Stytch configuration that Sites use for sign-in.
Site User site-user Belongs to one Auth Profile through authProfileId; supplies identity and an application role.
Text
site.authProfileId     -> auth-profile <- site-user.authProfileId
site.testAuthProfileId -> auth-profile (intended for local development)

A Site User can sign in to Sites that reference the same Auth Profile. Selecting a Test Auth Profile records the intended local profile; it does not configure the local application automatically. See About Auth Profiles.

Hosting is a separate Worker operation. A Site Worker uses managed-site-worker with SITE_ID to select the Site and IMAGE to select the application image. Follow Deploy and Update for those Site-specific selections and the Workers CLI Reference for image builds, create/update commands, deployment inspection, and logs.

Initialize Site Source

After you create a Site, use ctxl workers source to get its Astro starter as a GitHub repository or a local ZIP. Both commands require permission to read the Site and create Workers in the selected tenant.

Create a GitHub Repository

Use a GitHub Connection for the account that will own the repository. Replace github with its Connection ID. You need read and update permissions for the Connection and update permission for the Site.

Terminal
ctxl workers source clone astro-core --site customer-portal \
  --connection github --config-id my-config

The command creates a private GitHub repository, configures its Actions variables, and links it to the Site. The response includes the repository URL and the Worker ID. Use the URL with git clone to work on the code locally. To create a public repository, pass --public. If the repository name is taken or setup fails partway through, see Site Source Initialization Fails.

Download a ZIP

Terminal
ctxl workers source download astro-core --site customer-portal \
  --dir ./sites --config-id my-config

The command saves the same starter files and prints the ZIP path in the file field. It creates the destination directory if needed and defaults to the current directory when you omit --dir. Downloading a ZIP requires no GitHub Connection.

Choose Source and Worker Settings

Both commands accept --name to choose the repository or ZIP folder name and --branch to select a branch of the starter template. The generated contextual-deploy.env uses <site-id>-site-worker by default. To set a different Worker ID, pass --worker-id with an unused ID. An explicit ID that already exists returns 409. To download the starter again for an existing Worker with the default ID, omit --worker-id.

Inspect a Sites Resource

Read the deployed schema before preparing a payload. System types are not normally returned by ctxl types list; address site, auth-profile, or site-user explicitly:

Terminal
ctxl types get native-object:site --config-id my-config --pretty
ctxl types get native-object:auth-profile --config-id my-config --pretty
ctxl types get native-object:site-user --config-id my-config --pretty

Use projected lists for routine discovery. These commands omit provider credentials:

Terminal
ctxl records list \
  --type site \
  --fields id,name,authProfileId,testAuthProfileId \
  --config-id my-config --pretty

ctxl records list \
  --type auth-profile \
  --fields id,name,description,provider \
  --config-id my-config --pretty

ctxl records list \
  --type site-user \
  --exact-search authProfileId=customer-portal-auth \
  --fields id,email,name,role,authProfileId \
  --config-id my-config --pretty

Retrieve a specific record with --type and --id, for example:

Terminal
ctxl records get \
  --type site --id customer-portal \
  --config-id my-config --pretty

Your CLI identity needs read permission for inspection, create permission for new records, and update permission for patches on the corresponding type. Creating or deleting a Site User also needs Auth Profile permissions. Action execution has an additional permission requirement.

Create an Auth Profile or Site User

ctxl records add reads JSONL: one complete JSON object per line. Create an Auth Profile before adding its Site Users. For Site creation, use Create a Site in the console.

Create a Managed Auth Profile

Save this one-line object as auth-profile.jsonl:

JSON
{"id":"customer-portal-auth","name":"Customer portal authentication","description":"Users who can sign in to the customer portal","provider":"managed-stytch"}
Terminal
ctxl records add \
  --type auth-profile --input-file auth-profile.jsonl \
  --config-id my-config --pretty

This example creates a Managed Stytch profile; Contextual supplies the provider configuration. Create BYO Stytch profiles in the console so the Stytch secret stays out of shell commands, files, and coding-agent prompts. Keep the Auth Profile ID and provider unchanged after creation.

Create a Site User

Save this one-line object as site-user.jsonl:

JSON
{"email":"site.user@example.com","name":"Site User","role":"member","authProfileId":"customer-portal-auth"}
Terminal
ctxl records add \
  --type site-user --input-file site-user.jsonl \
  --config-id my-config --pretty

email, role, and authProfileId are required; name is optional. The role must be member or admin. Omit id so the platform generates it, and omit the provider-managed externalId. Record the returned ID for later updates. After either create, use the projected lists above to verify the saved values before continuing.

Apply Common Sites Updates

Inspect the current schema and record first. Keep the Site ID and the Auth Profile ID/provider unchanged. For Site Users, keep the ID, email, and Auth Profile unchanged; update the name or role.

Connect an existing Auth Profile to a Site:

Terminal
ctxl records patch \
  --type site --id customer-portal \
  --set authProfileId=customer-portal-auth \
  --config-id my-config --pretty

Follow Apply Site Configuration Changes for configuration refresh and pinned Site bindings. If the patch adds Managed Stytch to a running Site that had no authentication or used BYO Stytch, restart or update its Worker to register its origins. Then verify hosted sign-in, sign-out, and access to protected routes.

Change a Site User's application role, replacing SITE_USER_ID with the returned record ID:

Terminal
ctxl records patch \
  --type site-user --id SITE_USER_ID \
  --set role=admin \
  --config-id my-config --pretty

Retrieve the record again after a patch to verify the change. See Update a Site User for when saved name and role changes appear in the application.

Run Sites Actions

The Auth Profile's get-config action requires execute permission on auth-profile. Record read/create/update permissions do not grant action execution. If the permission editor does not expose the required Execute grant, or the action is forbidden, contact Contextual support with the CLI version, tenant and Auth Profile IDs, and the non-secret error.

Retrieve Local Auth Configuration

For the Astro starter's local development only, save this object as auth-config-params.json:

JSON
{"environment":"test"}
Terminal
ctxl records execute native-object:auth-profile/customer-portal-auth \
  --action-id get-config \
  --params-file auth-config-params.json \
  --config-id my-config --pretty

--params-file - reads the same JSON object from stdin. The result contains authProfileId, organizationSlug, projectId, and publicToken, without the Stytch secret. Put it in the authConfig field of the ignored site-auth.local.json file, following Use an Auth Profile During Local Development. A hosted Site Worker loads its configuration automatically.

For Managed Stytch, environment: "test" selects the managed test configuration. BYO profiles return their stored project configuration; choose the separate non-production profile for local development. See Configure BYO Stytch for Production and Local Development.

The Astro local helper invokes find-or-create-site-user automatically. Do not run it manually. Its ctxlConfigId setting selects a named CLI configuration; an empty value uses the current configuration. Keep CLI credentials separate from the Site repository.

Keep Authentication and Authorization Separate

Keep Stytch secrets in the Auth Profile and Tenant API credentials out of browser code and source control. A Site User role does not grant tenant API permissions; follow Site User Roles and Authorization when implementing server endpoints.