# Command line

Every method of the API as a command, for a terminal or a script.

## Get it

> The command comes with the SDK package, which is not on npm yet. Until it is published, run it from the repository, in `packages/opensend`.

```text
Usage: opensend <command>

  opensend login [--key <key>] [--url <address>]   Save the key, and the address of a server of your own
  opensend logout                                  Forget them
  opensend whoami                                  Say who the key belongs to
  opensend methods                                 List every command
  opensend <group> <action> [id] [--flags]         Call the API, for example:

  opensend emails send --from "Acme <hello@mail.example.com>" --to ada@example.com \
    --subject "Your receipt" --text "Thanks for your order."
  opensend domains list
  opensend emails get em_02c41d09b7e4

Every command takes --help, and --json with the whole input as JSON.
OPENSEND_API_KEY and OPENSEND_API_URL win over what login saved.
```

## Sign in

Give the key once. It is checked with a request, then saved. On a server of your own, give its address as well, with `--url`. Leave the key out and the command asks for it.

```bash
opensend login --key os_...
opensend whoami
opensend logout
```

- The key and the address are saved in `~/.config/opensend/config.json`, or under `$XDG_CONFIG_HOME` when that is set. Only you can read the file.
- `OPENSEND_API_KEY` and `OPENSEND_API_URL` in the environment win over the saved values, which suits a script or a CI job.
- `whoami` says who the key belongs to, and `logout` forgets the saved values.

## Run a command

A command is `opensend <group> <action>`, then the id when the method acts on one thing, then the input as flags. A flag is the name of the field with dashes: `scheduledAt` is `--scheduled-at`.

```bash
opensend emails list --status bounced --limit 20
opensend domains update dom_02 --click-tracking
opensend domains update dom_02 --click-tracking false
opensend webhooks create --url https://example.com/hooks/mail --events email.delivered,email.bounced
opensend emails send --tags '{"category":"receipt"}' --json '{"from":"Acme <hello@mail.example.com>","to":"ada@example.com","subject":"Hi","text":"Hello"}'
opensend emails send --help
```

| Field | Flag |
| --- | --- |
| Text or a number | `--subject "Your receipt"`, `--limit 20` |
| A switch | `--click-tracking` for yes, `--click-tracking false` for no |
| A list | `--to a@example.com,b@example.com`, or the flag once per value |
| An object | `--tags '{"category":"receipt"}'`, as JSON |

- `--json` takes the whole input as one JSON object. A flag beside it wins over the same field in it.
- `--help` after a command lists its flags and marks the ones it needs.
- `opensend <group>` lists the actions of a group, and `opensend methods` lists every command.

## Output

A command prints the answer of the API as JSON and ends with status 0. When it fails it prints the code and the message of the error on the error stream and ends with status 1, so a script can stop on it.

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

## Every command

| Command | What it does |
| --- | --- |
| opensend emails send | Send email |
| opensend emails batch | Send emails in a batch |
| opensend emails update | Reschedule email |
| opensend emails cancel | Cancel email |
| opensend emails get | Retrieve email |
| opensend emails list | List emails |
| opensend inbound list | List received emails |
| opensend inbound get | Retrieve received email |
| opensend domains create | Add domain |
| opensend domains verify | Verify domain |
| opensend domains get | Retrieve domain |
| opensend domains list | List domains |
| opensend domains update | Update domain |
| opensend domains remove | Delete domain |
| opensend templates create | Create template |
| opensend templates get | Get template |
| opensend templates list | List templates |
| opensend templates update | Update template |
| opensend templates edit | Edit template design |
| opensend templates publish | Publish template |
| opensend templates test | Send test of template |
| opensend templates render | Render template design |
| opensend templates duplicate | Duplicate template |
| opensend templates versions | List template versions |
| opensend templates version | Get template version |
| opensend templates restore | Restore template version |
| opensend templates remove | Delete template |
| opensend templates starters | List template starters |
| opensend templates starter | Get template starter |
| opensend images add | Add image |
| opensend images upload | Upload image |
| opensend images list | List images |
| opensend images get | Retrieve image |
| opensend images remove | Delete image |
| opensend broadcasts create | Create broadcast |
| opensend broadcasts update | Update broadcast |
| opensend broadcasts send | Send broadcast |
| opensend broadcasts test | Send test of broadcast |
| opensend broadcasts duplicate | Duplicate broadcast |
| opensend broadcasts get | Retrieve broadcast |
| opensend broadcasts list | List broadcasts |
| opensend broadcasts remove | Delete broadcast |
| opensend audiences create | Create audience |
| opensend audiences list | List audiences |
| opensend audiences get | Retrieve audience |
| opensend audiences update | Rename audience |
| opensend audiences remove | Delete audience |
| opensend audiences join | Add contact to audience |
| opensend audiences leave | Remove contact from audience |
| opensend contacts create | Add contact |
| opensend contacts list | List contacts |
| opensend contacts get | Retrieve contact |
| opensend contacts update | Update contact |
| opensend contacts remove | Delete contact |
| opensend contact-properties create | Create contact property |
| opensend contact-properties list | List contact properties |
| opensend contact-properties get | Retrieve contact property |
| opensend contact-properties update | Update contact property |
| opensend contact-properties remove | Delete contact property |
| opensend topics create | Create topic |
| opensend topics list | List topics |
| opensend topics get | Retrieve topic |
| opensend topics update | Update topic |
| opensend topics remove | Delete topic |
| opensend suppressions create | Suppress an address |
| opensend suppressions list | List suppressed addresses |
| opensend suppressions remove | Remove a suppressed address |
| opensend automations create | Create automation |
| opensend automations update | Update automation |
| opensend automations publish | Publish automation |
| opensend automations pause | Pause automation |
| opensend automations resume | Resume automation |
| opensend automations test | Test automation |
| opensend automations enroll | Enrol in automation |
| opensend automations duplicate | Duplicate automation |
| opensend automations get | Retrieve automation |
| opensend automations list | List automations |
| opensend automations remove | Delete automation |
| opensend runs list | List runs |
| opensend runs get | Retrieve run |
| opensend runs cancel | Cancel run |
| opensend runs retry | Retry run |
| opensend events send | Send event |
| opensend events create | Define event |
| opensend events list | List events |
| opensend events get | Retrieve event |
| opensend events update | Update event |
| opensend events remove | Delete event |
| opensend webhooks create | Add webhook |
| opensend webhooks list | List webhooks |
| opensend webhooks update | Update webhook |
| opensend webhooks remove | Delete webhook |
| opensend webhooks test | Send test event |
| opensend webhooks deliveries | List webhook deliveries |
| opensend metrics get | Retrieve metrics |
| opensend logs list | List logs |
| opensend logs get | Retrieve log |
| opensend api-keys create | Create API key |
| opensend api-keys enroll | Enroll existing API key |
| opensend api-keys list | List API keys |
| opensend api-keys remove | Revoke API key |
| opensend imports inspect | Look into another account |
| opensend imports create | Start import |
| opensend imports get | Retrieve import |
| opensend imports list | List imports |
| opensend imports cancel | Cancel import |
| opensend workspace get | Retrieve workspace |
| opensend workspace update | Update workspace |
| opensend workspace close | Close workspace |
| opensend members invite | Invite member |
| opensend members list | List members |
| opensend members update | Update member |
| opensend members remove | Remove member |
| opensend billing plans | List plans |
| opensend billing checkout | Start checkout |
| opensend billing portal | Open billing portal |
| opensend billing invoices | List invoices |
| opensend server get | Retrieve server settings |
| opensend server update | Update server settings |
| opensend account get | Retrieve account |
| opensend methods list | List methods |
| opensend ask send | Ask the assistant |
| opensend ask chats | List chats |
| opensend ask chat | Retrieve chat |
| opensend ask save | Keep chat |
| opensend ask forget | Forget chat |
