|
1 | 1 | # YNAB CLI |
2 | 2 |
|
3 | 3 | [](https://www.npmjs.com/package/@stephendolan/ynab-cli) |
4 | | -[](https://www.npmjs.com/package/@stephendolan/ynab-cli) |
5 | 4 | [](https://opensource.org/licenses/MIT) |
6 | | -[](https://bun.sh) |
7 | 5 |
|
8 | | -A command-line interface for You Need a Budget (YNAB) designed to enable LLMs (Claude, ChatGPT, etc.) and developers to quickly interface with YNAB budgets, make changes, and audit financial data. |
9 | | - |
10 | | -## Features |
11 | | - |
12 | | -- **LLM-First Design**: JSON output by default for easy parsing and integration with AI assistants |
13 | | -- **Advanced Filtering**: Built-in filters reduce need for external tools like `jq` - filter by approval status, amount ranges, field selection, and search capabilities |
14 | | -- **Comprehensive Coverage**: Support for all major YNAB API endpoints |
15 | | -- **Type Safety**: Built with TypeScript for robust error handling |
16 | | -- **Raw API Access**: Fallback command for any operation not covered by convenience commands |
17 | | -- **Simple Authentication**: Uses personal access tokens stored securely in OS keychain |
| 6 | +A command-line interface for YNAB designed for LLMs and developers. JSON output by default with built-in filtering. |
18 | 7 |
|
19 | 8 | ## Installation |
20 | 9 |
|
21 | | -Requires [Bun](https://bun.sh) runtime. |
| 10 | +Requires [Bun](https://bun.sh). |
22 | 11 |
|
23 | 12 | ```bash |
24 | | -# Install globally with bun (recommended) |
25 | 13 | bun install -g @stephendolan/ynab-cli |
26 | 14 |
|
27 | | -# Or run directly without installing |
| 15 | +# Or run without installing |
28 | 16 | bunx @stephendolan/ynab-cli budgets list |
29 | | -npx @stephendolan/ynab-cli budgets list # also works |
30 | 17 | ``` |
31 | 18 |
|
32 | | -### Linux Prerequisites |
33 | | - |
34 | | -Requires `libsecret` for keychain storage: |
| 19 | +<details> |
| 20 | +<summary>Linux: requires libsecret for keychain storage</summary> |
35 | 21 |
|
36 | 22 | ```bash |
37 | | -# Ubuntu/Debian |
38 | | -sudo apt-get install libsecret-1-dev |
39 | | - |
40 | | -# Fedora/RHEL |
41 | | -sudo dnf install libsecret-devel |
42 | | - |
43 | | -# Arch Linux |
44 | | -sudo pacman -S libsecret |
| 23 | +sudo apt-get install libsecret-1-dev # Ubuntu/Debian |
| 24 | +sudo dnf install libsecret-devel # Fedora/RHEL |
| 25 | +sudo pacman -S libsecret # Arch |
45 | 26 | ``` |
46 | 27 |
|
47 | | -Without `libsecret`, use the `YNAB_API_KEY` environment variable instead. |
48 | | - |
49 | | -### From Source |
50 | | - |
51 | | -```bash |
52 | | -git clone https://github.com/stephendolan/ynab-cli.git |
53 | | -cd ynab-cli |
54 | | -bun install |
55 | | -bun run link # Build and link globally |
56 | | -``` |
| 28 | +Without libsecret, use `YNAB_API_KEY` environment variable instead. |
| 29 | +</details> |
57 | 30 |
|
58 | 31 | ## Authentication |
59 | 32 |
|
60 | | -Set your YNAB personal access token using the CLI or environment variables: |
61 | | - |
62 | 33 | ```bash |
63 | | -ynab auth login # Interactive token entry, stored in OS keychain |
64 | | -ynab auth status # Check authentication status |
65 | | -ynab auth logout # Remove stored credentials |
| 34 | +ynab auth login # Store token in OS keychain |
| 35 | +ynab auth status # Check authentication |
| 36 | +ynab auth logout # Remove credentials |
66 | 37 | ``` |
67 | 38 |
|
68 | | -Or use environment variables (recommended for development): |
69 | | - |
70 | | -```env |
71 | | -YNAB_API_KEY=your_personal_access_token |
72 | | -YNAB_BUDGET_ID=your_default_budget_id # Optional |
73 | | -``` |
| 39 | +Or set `YNAB_API_KEY` environment variable. |
74 | 40 |
|
75 | | -## Usage |
| 41 | +## Commands |
76 | 42 |
|
77 | | -### Global Flags |
| 43 | +### Budgets |
78 | 44 |
|
79 | 45 | ```bash |
80 | | ---compact, -c # Minified JSON output (single line) |
| 46 | +ynab budgets list |
| 47 | +ynab budgets view [id] |
| 48 | +ynab budgets set-default <id> |
81 | 49 | ``` |
82 | 50 |
|
83 | | -### Commands |
84 | | - |
85 | | -#### User |
| 51 | +### Accounts |
86 | 52 |
|
87 | 53 | ```bash |
88 | | -ynab user info # Get authenticated user information |
| 54 | +ynab accounts list |
| 55 | +ynab accounts view <id> |
| 56 | +ynab accounts transactions <id> |
89 | 57 | ``` |
90 | 58 |
|
91 | | -#### Budgets |
| 59 | +### Categories |
92 | 60 |
|
93 | 61 | ```bash |
94 | | -ynab budgets list # List all budgets |
95 | | -ynab budgets view [id] # View budget details |
96 | | -ynab budgets settings [id] # View budget settings |
97 | | -ynab budgets set-default <id> # Set default budget |
98 | | -``` |
99 | | - |
100 | | -#### Accounts |
101 | | - |
102 | | -```bash |
103 | | -ynab accounts list # List all accounts |
104 | | -ynab accounts view <id> # View account details |
105 | | -ynab accounts transactions <id> # List transactions for account |
106 | | -``` |
107 | | - |
108 | | -#### Categories |
109 | | - |
110 | | -```bash |
111 | | -ynab categories list # List all categories |
112 | | -ynab categories view <id> # View category details |
| 62 | +ynab categories list |
| 63 | +ynab categories view <id> |
113 | 64 | ynab categories budget <id> --month <YYYY-MM> --amount <amount> |
114 | | -ynab categories transactions <id> # List transactions for category |
| 65 | +ynab categories transactions <id> |
115 | 66 | ``` |
116 | 67 |
|
117 | | -#### Transactions |
| 68 | +### Transactions |
118 | 69 |
|
119 | 70 | ```bash |
120 | | -# List and filter |
121 | | -ynab transactions list |
122 | | -ynab transactions list --account <id> |
123 | | -ynab transactions list --category <id> |
124 | | -ynab transactions list --payee <id> |
125 | | -ynab transactions list --since <YYYY-MM-DD> --until <YYYY-MM-DD> |
126 | | -ynab transactions list --approved=false |
127 | | -ynab transactions list --min-amount 100 --max-amount 500 |
128 | | -ynab transactions list --status=cleared,reconciled |
| 71 | +# List with filters |
| 72 | +ynab transactions list --account <id> --since <YYYY-MM-DD> |
| 73 | +ynab transactions list --approved=false --min-amount 100 |
129 | 74 | ynab transactions list --fields id,date,amount,memo |
130 | 75 |
|
131 | 76 | # Search |
132 | 77 | ynab transactions search --memo "coffee" |
133 | 78 | ynab transactions search --payee-name "Amazon" |
134 | | -ynab transactions search --amount 42.50 |
135 | 79 |
|
136 | | -# CRUD operations |
| 80 | +# CRUD |
137 | 81 | ynab transactions view <id> |
138 | | -ynab transactions create |
139 | 82 | ynab transactions create --account <id> --amount <amount> --date <YYYY-MM-DD> |
140 | 83 | ynab transactions update <id> --amount <amount> |
141 | 84 | ynab transactions delete <id> |
142 | | -ynab transactions import |
143 | | -ynab transactions split <id> --splits '[{"amount": -50.00, "category_id": "xxx", "memo": "..."}]' |
| 85 | +ynab transactions split <id> --splits '[{"amount": -50.00, "category_id": "xxx"}]' |
144 | 86 | ``` |
145 | 87 |
|
146 | | -#### Scheduled Transactions |
| 88 | +### Payees |
147 | 89 |
|
148 | 90 | ```bash |
149 | | -ynab scheduled list # List all scheduled transactions |
150 | | -ynab scheduled view <id> # View scheduled transaction |
151 | | -ynab scheduled delete <id> # Delete scheduled transaction |
| 91 | +ynab payees list |
| 92 | +ynab payees view <id> |
| 93 | +ynab payees update <id> --name <name> |
| 94 | +ynab payees transactions <id> |
152 | 95 | ``` |
153 | 96 |
|
154 | | -#### Payees |
| 97 | +### Months |
155 | 98 |
|
156 | 99 | ```bash |
157 | | -ynab payees list # List all payees |
158 | | -ynab payees view <id> # View payee details |
159 | | -ynab payees update <id> --name <name> # Rename payee |
160 | | -ynab payees locations <id> # List locations for payee |
161 | | -ynab payees transactions <id> # List transactions for payee |
| 100 | +ynab months list |
| 101 | +ynab months view <YYYY-MM> |
162 | 102 | ``` |
163 | 103 |
|
164 | | -#### Months |
| 104 | +### Scheduled Transactions |
165 | 105 |
|
166 | 106 | ```bash |
167 | | -ynab months list # List all budget months |
168 | | -ynab months view <YYYY-MM> # View specific month details |
| 107 | +ynab scheduled list |
| 108 | +ynab scheduled view <id> |
| 109 | +ynab scheduled delete <id> |
169 | 110 | ``` |
170 | 111 |
|
171 | | -#### Raw API Access |
| 112 | +### Raw API Access |
172 | 113 |
|
173 | 114 | ```bash |
174 | | -ynab api <method> <path> [--data <json>] |
175 | | - |
176 | | -# Examples: |
177 | 115 | ynab api GET /budgets |
178 | | -ynab api GET /budgets/{budget_id}/transactions |
179 | 116 | ynab api POST /budgets/{budget_id}/transactions --data '{"transaction": {...}}' |
180 | 117 | ``` |
181 | 118 |
|
182 | | -## Output Format |
| 119 | +## Output |
183 | 120 |
|
184 | | -All commands return JSON by default: |
| 121 | +All commands return JSON. Use `--compact` for minified output. |
185 | 122 |
|
186 | | -- **Lists**: Arrays of objects (not wrapped) |
187 | | -- **Single items**: Objects directly |
188 | | -- **Errors**: `{"error": {"name": "...", "detail": "...", "statusCode": 400}}` |
189 | | - |
190 | | -## Currency Format |
191 | | - |
192 | | -**All amounts are in dollars.** The CLI automatically converts YNAB's internal milliunit format (1000 = $1.00) in both input and output. |
193 | | - |
194 | | -- Input: `--min-amount 100` means $100 |
195 | | -- Output: `"amount": -555.28` means -$555.28 |
| 123 | +**Amounts are in dollars** (not YNAB's internal milliunits). `--min-amount 100` means $100. |
196 | 124 |
|
197 | 125 | ## API Limitations |
198 | 126 |
|
199 | | -The YNAB API does not support: |
200 | | - |
201 | | -- Creating categories, category groups, or payees |
202 | | -- Updating accounts (beyond initial creation) |
203 | | - |
204 | | -Use the YNAB web or mobile app for these operations. |
205 | | - |
206 | | -## API Rate Limits |
207 | | - |
208 | | -The YNAB API enforces a rate limit of **200 requests per hour** per access token. When exceeded, the API returns HTTP 429 errors. |
| 127 | +The YNAB API does not support creating categories, category groups, or payees. Use the web or mobile app for these. |
209 | 128 |
|
210 | | -**If you hit the rate limit:** |
211 | | -- Wait 5-10 minutes before retrying (the limit uses a rolling 60-minute window) |
212 | | -- For batch operations, add delays between requests: `sleep 20` in shell loops ensures ~180 requests/hour |
| 129 | +Rate limit: 200 requests/hour per token. If exceeded, wait 5-10 minutes. |
213 | 130 |
|
214 | 131 | ## References |
215 | 132 |
|
216 | 133 | - [YNAB API Documentation](https://api.ynab.com/) |
217 | | -- [YNAB JavaScript SDK](https://github.com/ynab/ynab-sdk-js) |
218 | 134 | - [Specification](./SPEC.md) |
219 | 135 |
|
220 | 136 | ## License |
|
0 commit comments