# CLI

Use the Monta Partner API from your terminal — every endpoint as a command.

# CLI

The Monta API CLI (`monta`) lets you call the Monta API directly from your terminal. Every API endpoint is available as a command, so you can script automations, run quick lookups, and pipe results into other tools — without writing any integration code.

## What can it do?

* **Full API coverage** — one command per Monta API endpoint, always in sync with the API
* **Scriptable** — ideal for bulk operations, scheduled jobs, and CI/CD pipelines
* **Multiple output formats** — JSON, table, CSV, or raw (for piping to `jq`)
* **Multi-profile auth** — switch between production, staging, and test credentials
* **OAuth handled for you** — pass your Client ID and Secret; token refresh is automatic

## Installation

Requires [Node.js](https://nodejs.org) 18 or newer.

### npm (recommended)

Install globally to get the `monta` command everywhere:

```bash
npm install -g @monta-api/cli
monta --help
```

### npx (no install)

Run without installing:

```bash
npx @monta-api/cli charge-points list
```

### Launcher script

Download a self-contained launcher (no npm required) — it fetches and caches the CLI, auto-updating every 24 hours:

```bash
curl -o monta-cli.sh https://partner-api-mcp.monta.app/scripts/monta-cli.sh
chmod +x monta-cli.sh
./monta-cli.sh --help
```

## Authentication

Authenticate with the same Client ID and Client Secret you use for the Monta API. The CLI resolves credentials in this order (highest priority first):

| Priority | Method                | Example                                              |
| -------- | --------------------- | ---------------------------------------------------- |
| 1        | CLI flags             | `monta --client-id X --client-secret Y charges list` |
| 2        | Environment variables | `MONTA_CLIENT_ID` + `MONTA_CLIENT_SECRET`            |
| 3        | Bearer token          | `MONTA_BEARER_TOKEN`                                 |
| 4        | Saved profile         | created with `monta auth login`                      |

:::info{title="Don't have credentials yet?"}

See [Authentication](/reference/ref-authentication) for how to obtain a Client ID and Client Secret.

:::

### Save your credentials

Store credentials once so you don't repeat them on every command:

```bash
monta --client-id YOUR_ID --client-secret YOUR_SECRET auth login
monta auth whoami
```

To keep separate credentials for different environments, use named profiles:

```bash
# Save staging credentials under a profile
monta --client-id STG_ID --client-secret STG_SECRET --profile staging auth login

# Use that profile
monta --profile staging charge-points list
```

## Quick start

```bash
# List your charge points
monta charge-points list

# Get a single charge point
monta charge-points get 12345

# List charges (sessions) in a date range
monta charges list --state completed --fromDate 2024-01-01 --toDate 2024-12-31

# Start a charge
monta charges create --body '{"chargePointId": 12345}'
```

Commands follow a predictable pattern based on the API:

| HTTP method                  | CLI action | Example                                 |
| ---------------------------- | ---------- | --------------------------------------- |
| `GET /resource`              | `list`     | `monta charge-points list`              |
| `GET /resource/{id}`         | `get`      | `monta charge-points get 12345`         |
| `POST /resource`             | `create`   | `monta sites create --body '{...}'`     |
| `PATCH`/`PUT /resource/{id}` | `update`   | `monta sites update 456 --body '{...}'` |
| `DELETE /resource/{id}`      | `delete`   | `monta sites delete 456`                |

Run `monta --help`, or `monta <resource> --help`, to discover every available command.

## Output formats

Use `-o` / `--output` to control how results are printed:

```bash
monta charges list -o table     # aligned ASCII table
monta charges list -o csv        # CSV, ready for spreadsheets
monta charges list -o raw | jq   # compact JSON for piping
```

`json` (pretty-printed) is the default.
