# CLI

> Script the Management API from your terminal, generate TypeScript types for a site's collections, and check a headless front end's setup.

> Markdown version of https://kanorio.com/en/developers/cli. Append `.md` to any developer docs URL for this format. Index: https://kanorio.com/llms.txt · MCP: https://app.kanorio.com/api/mcp

The Kanorio CLI wraps the Management API for scripts and CI, and adds two developer tools: type generation and a health check for headless front ends.

```bash
npx @kanorio/cli --help
```

## Sign in

```bash
npx @kanorio/cli login --token knr_pat_...
```

The token is stored in `~/.config/kanorio/config.json` with owner-only permissions. In CI, set `KANORIO_TOKEN` instead. It takes precedence over the stored token. A [service account](https://kanorio.com/en/developers/authentication) token works too.

## Common commands

```bash
kanorio sites list
kanorio pages list ws_example123
kanorio pages replace-sections ws_example123 pg_example456 --file sections.json
kanorio media upload ws_example123 --file hero.jpg
kanorio publish ws_example123
kanorio domains status ws_example123
```

Commands that overwrite content read the resource first and send its timestamp, so they fail with `CONFLICT` instead of overwriting someone's edits. Run `kanorio --help` for the full list.

## Output and exit codes

- Add `--json` to print the raw API response, including errors, for scripting.
- Errors print as `<CODE> (HTTP <status>): <message>` on stderr and exit with `1`. Usage errors exit with `2`.
- Warnings about deprecated operations go to stderr.

## Generate types

```bash
kanorio types --site https://s-xxxxxxxxxxxx.kanorio.com --out src/kanorio.d.ts
```

`types` reads the site's public collection schema and writes `FieldData`, `Expanded` and `Item` types for every collection, plus the types for pages, globals and site metadata. Run it again when the schema changes, or subscribe to the `collections.schema.changed` webhook to automate it.

## Check a headless front end

```bash
kanorio doctor --site ws_example123
```

`doctor` checks that your front end serves the sitemap, robots.txt, llms.txt, feeds, JSON-LD and the IndexNow key file, that page content is in sync, and that pageviews and webhooks are arriving. Add `--switching` before you move a domain from a Kanorio-hosted site to your own front end.
