# CLI API

> The device flow the dna CLI signs in with. Every cli endpoint with its scope, parameters, body and an example answer.

Source: https://docs.dissolve.email/reference/cli

Base URL `https://api.dissolve.email`. These endpoints take no bearer token.

| Endpoint | Summary |
|---|---|
| `POST /api/cli/device` | [Start the CLI device flow](#start-the-cli-device-flow) |
| `POST /api/cli/token` | [Poll for the CLI's key](#poll-for-the-cli-s-key) |

### Start the CLI device flow

`POST /api/cli/device`

Asks for a one-time code to show the person and a device code to poll with. The person opens `verification_url`, checks the code and approves. Ten a minute per address.

```bash cURL
curl -X POST "https://api.dissolve.email/api/cli/device"
```

```python Python
import os, requests

response = requests.post("https://api.dissolve.email/api/cli/device")
print(response.json())
```

**Response** `200`

```json
{
  "device_code": "dc_...",
  "user_code": "WDJB-MJHT",
  "verification_url": "https://app.dissolve.email/cli/auth",
  "expires_in": 600,
  "interval": 5
}
```

### Poll for the CLI's key

`POST /api/cli/token`

Answers 400 `authorization_pending` until the person approves, then once with a new `sk_live_` key (Pro and Business). `access_denied` and `expired_token` end the flow.

**Body** (`application/json`)

| Name | Type | Required | Description |
|---|---|---|---|
| `device_code` | string | yes | From POST /api/cli/device. |

```bash cURL
curl -X POST "https://api.dissolve.email/api/cli/token" \
  -H "Content-Type: application/json" \
  -d '{"device_code":"dc_..."}'
```

```python Python
import os, requests

response = requests.post("https://api.dissolve.email/api/cli/token", json={
  "device_code": "dc_..."
})
print(response.json())
```

**Response** `200`

```json
{
  "api_key": "sk_live_..."
}
```
