# Brex Bank

Fetch transactions from Brex cash (bank) accounts.

## Setup

Use the same API token as [Brex Card](https://docs.visigrid.app/connections/brex-card/) — a single Brex token covers both card and bank.

```bash
export BREX_API_KEY=brex_token_...
```

## Usage

```bash
vgrid fetch brex-bank --from 2026-01-01 --to 2026-02-01 --out brex-bank.csv
```

If you have multiple active cash accounts, specify one with `--account`:

```bash
vgrid fetch brex-bank --account cash_abc --from 2026-01-01 --to 2026-02-01 --out brex-bank.csv
```

## Options

| Flag | Description | Default |
|------|-------------|---------|
| `--from` | Start date inclusive (YYYY-MM-DD) | required |
| `--to` | End date exclusive (YYYY-MM-DD) | required |
| `--api-key` | Brex API token | `BREX_API_KEY` env |
| `--account` | Brex cash account ID | auto-detected |
| `--out` | Output CSV path | stdout |
| `-q` / `--quiet` | Suppress progress messages | off |

## Type mapping

| Brex cash type | Canonical type |
|----------------|----------------|
| `PAYMENT`, `PAYMENT_FAILED` | `withdrawal` |
| `DEPOSIT`, `RECEIVED` | `deposit` |
| `TRANSFER`, `BOOK_TRANSFER` | `transfer` |
| `CARD_SETTLEMENT` | `expense` |
| `FEE` | `fee` |
| `INTEREST` | `interest` |
| `RETURN`, `REVERSAL` | sign-based (`deposit` or `withdrawal`) |
| `ACH_TRANSFER`, `ACH` | sign-based |
| `WIRE_TRANSFER`, `WIRE` | sign-based |
| _anything else_ | sign-based |

## Date handling

- **`effective_date`** — `initiated_at_date` (when the transaction was initiated)
- **`posted_date`** — `posted_at_date` (when it settled); falls back to `initiated_at_date` if absent

The `--to` flag is exclusive: internally converted to inclusive by subtracting one day.

## Notes

**Account auto-detection.** If `--account` is omitted, VisiGrid lists cash accounts and selects the single active one. If there are zero or multiple active accounts, it errors with a list of account names.

**Description fallback.** `description` field, then `memo`.

**`source` field.** `brex` (shared with other Brex adapters).

**Pagination.** Cursor-based (`next_cursor`) with stuck-cursor detection.

**Sort order.** `posted_date` ascending, then `source_id` ascending.