# Brex Card

Fetch card transactions from Brex.

## Setup

Generate an API token at [Brex Dashboard > Developer > API tokens](https://dashboard.brex.com/settings/developer) with read access to transactions.

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

## Usage

```bash
vgrid fetch brex-card --from 2026-01-01 --to 2026-02-01 --out brex-card.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 |
| `--out` | Output CSV path | stdout |
| `-q` / `--quiet` | Suppress progress messages | off |

## Type mapping

| Brex type | Canonical type | Sign |
|-----------|----------------|------|
| `PURCHASE` | `purchase` | negative (outflow) |
| `REFUND` | `refund` | positive (inflow) |
| `CHARGEBACK` | `chargeback` | positive (inflow) |
| `COLLECTION` | `collection` | negative (outflow) |
| `REWARDS_CREDIT` | `credit` | positive (inflow) |
| _anything else_ | `adjustment` | negative (outflow) |

## Date handling

- **`effective_date`** — `posted_at_date` from Brex
- **`posted_date`** — same as `effective_date` (Brex card transactions only provide a posted date)

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

## Notes

**Amounts.** Brex provides amounts in minor units (cents) — no float conversion needed.

**`group_id`.** Set to the `card_id`, grouping transactions by physical card.

**`source` field.** `brex_card`.

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

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