# Output and scripts

Tables for people, JSON for programs, and exit codes a script can trust.

## What it prints

In a terminal, a list is a table and one item is a list of its fields. Anywhere else, such as a pipe, a file or a CI job, a command prints the answer of the API as JSON, as it came. `--json` asks for JSON in a terminal too.

```bash
opensend emails get em_02 | jq -r .status
```

Notes meant for a person, such as one that says there are more pages, go to the error stream, so they never mix with the JSON.

## Every page of a list

A list answers one page at a time. `--all` reads every page and prints them as one list, and `--max` stops after that many items, with or without `--all`. A read the API answers with 429, 502, 503 or 504 is tried up to three times in all, after the wait it asks for.

```bash
opensend emails list --all --max 500 | jq '.data | length'
```

## See the request first

`--dry-run` prints the request a command would send, its verb, address and body, and sends nothing. It works before you sign in. Commands that act only on this computer, such as `login` and `mcp serve`, refuse it.

```bash
opensend emails send --to ada@example.com --subject Hi --text Hello --dry-run
```

## Removing things

A command that deletes something asks first when it runs in a terminal: every command the reference marks as removing, and `api` with `DELETE`. Anywhere else it refuses unless it has `--yes`, and `--no-input` makes it refuse instead of asking, even in a terminal. Ctrl+C at the question stops it with code 130.

```bash
opensend domains remove dom_02 --yes
```

## Errors

An error goes to the error stream: its message, then its code, the HTTP status and the request id when there is one. With `--json` it is one JSON object, `{ "error": { ... } }`, with the same four fields. The code is the API's own when the API answered, and the one in this table when the command stopped by itself.

| Exit | Code | Meaning |
| --- | --- | --- |
| `0` |  | It worked. |
| `1` | `failed` | The API refused the request, or something else failed. |
| `2` | `usage` | A command, a flag or a value is wrong. Nothing was sent. |
| `3` | `signed_out` | No key was found, or the API refused it. |
| `4` | `not_found` | What the command names does not exist. |
| `5` | `rate_limited` | Too many requests. Wait a moment, then try again. |
| `6` | `unreachable` | The API could not be reached, or failed on its side. |
| `7` | `unconfirmed` | A removal was not confirmed, so nothing was removed. |
| `130` |  | Stopped with Ctrl+C. |

## Versions

The command line follows semantic versioning. A minor version adds commands and flags. A major version is the only one that removes or changes one, changes an exit code or raises the lowest version of Node.js.

An installed command line still reaches what the API adds after it: `opensend api` sends any request, and `opensend mcp serve` passes on the tools the server lists. `opensend --version` prints yours, and [the CLI changelog](https://opensend.sh/changelog/cli) lists every version.

## In a CI job

```bash
export OPENSEND_API_KEY=...
opensend emails send --input @release-mail.json --no-input
```

Keep the key in a secret of the job, never in the command itself. `--no-input` makes sure nothing waits for an answer, and the exit code tells the job whether OpenSend took the request.
