> ## Documentation Index
> Fetch the complete documentation index at: https://docs.occtoo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scripting and CI

> Output formats, JSON input, confirmations and exit codes for scripts, CI jobs and agents

Every command works without a person at the keyboard. This page explains how to drive the CLI from a script, a CI job or an AI agent.

## Output formats

Commands that read print a table for people by default. Add `--output json` (or `-o json`) to get JSON instead:

```bash theme={null}
occtoo sources list                  # a table
occtoo sources list --output json    # JSON
```

The JSON uses the same field names as the [REST API](https://docs.occtoo.com/api-reference/overview.md), so you can use the API reference to read it. Pipe it to a tool like [`jq`](https://jqlang.org):

```bash theme={null}
occtoo sources list --output json | jq -r '.[].id'
```

A few commands print a stream of events instead of a table. They take `--output text` (the default, one readable line per event) or `--output json` (one JSON document per line):

* `occtoo events subscribe`
* `occtoo events list`
* `occtoo events destinations pull` (here `json` prints the whole batch as one document)

## Data on stdout, messages on stderr

The CLI writes data to stdout and everything meant for people to stderr: prompts, spinners, progress bars and errors. That means you can pipe or redirect the output and still see progress in your terminal:

```bash theme={null}
occtoo cards entries search products --properties name,price --output json > products.json
```

## JSON input

Commands that write, such as `create` and `edit`, take their input in one of two ways:

* **Prompts.** In a terminal, the CLI asks you for each value.
* **JSON.** Pass a JSON file with `--file` (or `-f`), or pipe JSON to stdin.

```bash theme={null}
occtoo sources create --file source.json
echo '{"id": "products", "name": "Products"}' | occtoo sources create
```

The JSON uses the API's field names. The CLI rejects a field it doesn't know, so a typo fails loudly instead of being ignored. Run a command with `--help` to see the JSON it takes, with an example.

For `edit` commands, a field you leave out stays as it is.

## No prompts outside a terminal

The CLI only asks questions when both stdin and stderr are a terminal. In a script it never waits for input. If it needs something you didn't give, it stops with an error that names the flag or environment variable to set.

Interactive pickers are only a shortcut. Everything they do is also possible with arguments, flags and JSON input.

## Confirm deletes with `--yes`

Commands that delete or throw away data ask for confirmation in a terminal. In a script, pass `--yes` (or `-y`). Without it, the command fails and tells you to pass `--yes`.

```bash theme={null}
occtoo sources entries delete products sku-1 --yes
```

## Exit codes

| Code | Meaning |
| - | - |
| `0` | The command succeeded |
| `1` | The command failed. The error is printed on stderr |
| `130` | You cancelled the command, for example with Ctrl-C |

Error messages say what failed and what to do next. When a request to the API fails, the message includes the trace id of the request, which helps Occtoo support find it.

## Long-running work

Some commands start work that runs in the background in Occtoo and wait until it is done, for example `occtoo cards activate`, `occtoo lifecycles activate`, `occtoo destinations publish` and `occtoo cards export`. Progress goes to stderr. Ctrl-C stops the waiting, not the work itself. Use the matching `show` command to check how far it is.

## Example: CI job

This GitHub Actions job imports a product file every night with an application's credentials:

```yaml theme={null}
name: Import products
on:
  schedule:
    - cron: "0 2 * * *"
jobs:
  import:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install the Occtoo CLI
        run: cargo install --git https://github.com/Occtoo/cli occtoo-cli
      - name: Import products
        env:
          OCCTOO_CLIENT_ID: ${{ secrets.OCCTOO_CLIENT_ID }}
          OCCTOO_CLIENT_SECRET: ${{ secrets.OCCTOO_CLIENT_SECRET }}
        run: occtoo sources import products data/products.csv --yes --output json
```

See [Authentication](https://docs.occtoo.com/cli/authentication.md) for how the CLI picks a credential.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.