# CLI

The askads command line tool, for people at a terminal and for scripts. Sign in with your browser or a key, then read, build paused drafts, pause and ask for approval.

## Install

```bash
npx askads --version          # no install, needs Node 18 or later
npm install -g askads         # or keep it installed
```

Single-file downloads that need no Node at all (macOS on Apple silicon and Intel, Linux x64 and arm64, Windows x64, each with a checksum) will be linked here once they are published.

## Sign in

```bash
askads login                  # opens your browser: check the code, pick the team and scopes, press Allow
askads login --no-browser     # prints the link and the code to open on another device
askads login --key -          # reads an API key from stdin (keeps it out of your shell history)
askads whoami
askads logout
```

`askads logout` revokes the saved key at AskAds (`POST /me/revoke`, which only ever ends the key making the call) and then forgets it on this computer. If AskAds cannot be reached, the key is still forgotten here and the CLI says where to revoke it by hand. A key in `ASKADS_API_KEY` is never revoked by logout.

If `ASKADS_API_KEY` is set, the CLI uses it and needs no login. `--base-url` (or `ASKADS_BASE_URL`) points it at another address.

The browser login makes an `ask_cli_` key that lasts 90 days and shows in the dashboard under **Developers**, where you can revoke it. [How the browser login works](/developers/authentication#cli-login). The CLI keeps it in `~/.config/askads/config.json`, readable only by you, and never prints it again.

## Commands

One command per API operation, grouped by what it works on. Ids in the address are given in order after the command; every other field is a `--flag` named like the field (`dailyBudget` is `--daily-budget`). For a bigger body, `--file draft.json` (or `--file -` for stdin) or `--data '{...}'`; flags win over the file.

```bash
askads status
askads accounts list
askads report acc_123 --period last_7_days
askads campaigns list acc_123
askads campaigns get acc_123 120211234567890
askads drafts create acc_123 --file draft.json
askads approvals request-launch --ad-account-id acc_123 --level campaign --id 120211234567890
askads approvals request-raise --ad-account-id acc_123 --level campaign --id 120211234567890 --daily-budget 50
askads approvals list
askads approvals wait chg_123            # waits until a person decides; prints the approval link
askads pause acc_123 ad 120219876543210
askads budget lower acc_123 campaign 120211234567890 --daily-budget 20
askads stop-all-changes --yes
askads webhooks create --url https://example.com/hooks/askads --events approval.requested,item.paused
askads webhooks verify --secret "$ASKADS_WEBHOOK_SECRET" --signature "$SIGNATURE" --file body.json
askads mcp config --agent claude-code    # or codex, cursor; add --with-key to use ASKADS_API_KEY
askads openapi                           # prints the API spec
askads help report                       # the flags of any command
```

Every operation in the [API reference](/developers/api) has a command; `askads help` lists them all. There is no approve command. `askads approvals wait` prints the link a person opens to approve on the website, and exits when they decide. `stop-all-changes` asks for `--yes`, because only a person on the website can switch it off again.

## Output

- On a terminal: tables for people.
- With `--json`, or whenever the output goes to a pipe or a file: JSON, one answer per command, ready for `jq`.

## Exit codes

| Code | Means |
|---|---|
| 0 | Done. |
| 1 | An error. The message says what happened. |
| 2 | The command was used the wrong way. See `--help`. |
| 3 | Not signed in, or the key expired or was revoked. Run `askads login`. |
| 4 | Waiting for a person to approve. |

## In CI

In GitHub Actions, keep the key in a secret:

```yaml
- run: npx askads accounts list --json > accounts.json
  env:
    ASKADS_API_KEY: ${{ secrets.ASKADS_API_KEY }}
```

Use a key with only the scopes the job needs, and give it an expiry.
