@ktmcp-cli/billingo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example ADDED
@@ -0,0 +1,8 @@
1
+ # Billingo API Configuration
2
+ # Copy this file to .env and fill in your values
3
+
4
+ # Get your API key from: https://app.billingo.hu/api-key
5
+ BILLINGO_API_KEY=your_api_key_here
6
+
7
+ # API base URL (usually no need to change this)
8
+ BILLINGO_BASE_URL=https://api.billingo.hu/v3
package/AGENT.md ADDED
@@ -0,0 +1,447 @@
1
+ # Billingo CLI - AI Agent Usage Guide
2
+
3
+ This guide is designed for AI agents (like Claude, GPT-4, etc.) to effectively use the Billingo CLI.
4
+
5
+ ## Quick Start for Agents
6
+
7
+ ### 1. Configuration Check
8
+
9
+ Before making any API calls, verify the API key is configured:
10
+
11
+ ```bash
12
+ billingo config get apiKey
13
+ ```
14
+
15
+ If not set, configure it:
16
+
17
+ ```bash
18
+ billingo config set apiKey YOUR_API_KEY
19
+ ```
20
+
21
+ ### 2. Common Workflows
22
+
23
+ #### Create and Send an Invoice
24
+
25
+ ```bash
26
+ # Step 1: Create invoice from JSON
27
+ billingo documents create --file invoice.json
28
+
29
+ # Step 2: Get the document ID from response (e.g., 789)
30
+
31
+ # Step 3: Download PDF
32
+ billingo documents download 789 --output invoice-789.pdf
33
+
34
+ # Step 4: Send to customer
35
+ billingo documents send 789 --emails "customer@example.com"
36
+ ```
37
+
38
+ #### List Recent Unpaid Invoices
39
+
40
+ ```bash
41
+ billingo documents list \
42
+ --payment-status unpaid \
43
+ --start-date 2024-01-01 \
44
+ --per-page 50 \
45
+ --format json
46
+ ```
47
+
48
+ #### Create Partner and Product, Then Invoice
49
+
50
+ ```bash
51
+ # Step 1: Create partner
52
+ billingo partners create --data '{
53
+ "name": "New Customer Ltd.",
54
+ "address": {
55
+ "country_code": "HU",
56
+ "post_code": "1234",
57
+ "city": "Budapest",
58
+ "address": "Main St 1"
59
+ },
60
+ "emails": ["customer@example.com"]
61
+ }'
62
+
63
+ # Step 2: Get partner ID from response (e.g., 456)
64
+
65
+ # Step 3: Create document with partner
66
+ billingo documents create --file invoice.json
67
+ # (invoice.json must include "partner_id": 456)
68
+ ```
69
+
70
+ ## Output Parsing
71
+
72
+ ### JSON Format (Recommended for Agents)
73
+
74
+ Always use `--format json` when you need to parse the output programmatically:
75
+
76
+ ```bash
77
+ billingo documents list --format json
78
+ ```
79
+
80
+ This returns structured JSON that's easy to parse:
81
+
82
+ ```json
83
+ {
84
+ "data": [
85
+ {
86
+ "id": 123,
87
+ "invoice_number": "INV-2024-001",
88
+ "partner_name": "Customer Name",
89
+ "total_gross": 127000,
90
+ "currency": "HUF",
91
+ "payment_status": "paid"
92
+ }
93
+ ],
94
+ "current_page": 1,
95
+ "total": 42
96
+ }
97
+ ```
98
+
99
+ ### Pretty Format (Human-Readable)
100
+
101
+ Default format is good for displaying to users:
102
+
103
+ ```bash
104
+ billingo documents get 789
105
+ # Returns nicely formatted output for humans
106
+ ```
107
+
108
+ ## Data Input Methods
109
+
110
+ ### Method 1: File-Based (Recommended for Complex Data)
111
+
112
+ ```bash
113
+ # Save data to file
114
+ cat > invoice.json << 'EOF'
115
+ {
116
+ "vendor_id": 1,
117
+ "partner_id": 123,
118
+ "block_id": 1,
119
+ "type": "invoice",
120
+ "fulfillment_date": "2024-01-15",
121
+ "due_date": "2024-01-30",
122
+ "payment_method": "transfer",
123
+ "language": "hu",
124
+ "currency": "HUF",
125
+ "items": [
126
+ {
127
+ "name": "Service",
128
+ "unit_price": 50000,
129
+ "quantity": 10,
130
+ "unit": "hour",
131
+ "vat": "27%"
132
+ }
133
+ ]
134
+ }
135
+ EOF
136
+
137
+ # Use the file
138
+ billingo documents create --file invoice.json
139
+ ```
140
+
141
+ ### Method 2: Inline JSON (For Simple Data)
142
+
143
+ ```bash
144
+ billingo partners create --data '{"name":"Quick Partner","emails":["test@example.com"]}'
145
+ ```
146
+
147
+ ## Error Handling for Agents
148
+
149
+ ### Check Exit Codes
150
+
151
+ The CLI uses standard exit codes:
152
+ - `0` - Success
153
+ - `1` - Error (check stderr for details)
154
+
155
+ Example in bash:
156
+
157
+ ```bash
158
+ if billingo documents get 789 --format json > document.json; then
159
+ echo "Success"
160
+ else
161
+ echo "Failed with exit code $?"
162
+ fi
163
+ ```
164
+
165
+ ### Common Error Patterns
166
+
167
+ **API Key Not Configured:**
168
+ ```
169
+ Error: API key not configured. Set it with: billingo config set apiKey <your-api-key>
170
+ ```
171
+
172
+ **Resource Not Found:**
173
+ ```
174
+ Error: Resource not found.
175
+ ```
176
+
177
+ **Validation Error:**
178
+ ```
179
+ Error: Validation error: {"field":"partner_id","message":"required"}
180
+ ```
181
+
182
+ **Rate Limit:**
183
+ ```
184
+ Error: Rate limit exceeded. Retry after 60 seconds.
185
+ ```
186
+
187
+ ### Handling Rate Limits
188
+
189
+ Monitor warnings in stderr:
190
+ ```
191
+ Warning: Only 5/60 API calls remaining in this window
192
+ ```
193
+
194
+ Implement exponential backoff:
195
+ 1. Wait 1 second, retry
196
+ 2. Wait 2 seconds, retry
197
+ 3. Wait 4 seconds, retry
198
+ 4. etc.
199
+
200
+ ## Pagination Best Practices
201
+
202
+ When listing resources, handle pagination properly:
203
+
204
+ ```bash
205
+ # Get first page
206
+ billingo documents list --page 1 --per-page 25 --format json > page1.json
207
+
208
+ # Check if more pages exist (look at "last_page" field)
209
+
210
+ # Get next page
211
+ billingo documents list --page 2 --per-page 25 --format json > page2.json
212
+ ```
213
+
214
+ Response includes pagination metadata:
215
+ ```json
216
+ {
217
+ "data": [...],
218
+ "current_page": 1,
219
+ "last_page": 5,
220
+ "per_page": 25,
221
+ "total": 120,
222
+ "next_page_url": "...",
223
+ "prev_page_url": null
224
+ }
225
+ ```
226
+
227
+ ## Resource ID Management
228
+
229
+ ### Getting IDs from Create Operations
230
+
231
+ When you create a resource, the response includes its ID:
232
+
233
+ ```bash
234
+ billingo partners create --file partner.json --format json
235
+ # Response: {"id": 456, "name": "...", ...}
236
+ ```
237
+
238
+ Extract the ID (example with jq):
239
+ ```bash
240
+ ID=$(billingo partners create --file partner.json --format json | jq -r '.id')
241
+ echo "Created partner with ID: $ID"
242
+ ```
243
+
244
+ ### Converting Legacy IDs
245
+
246
+ If you have IDs from Billingo API v2:
247
+
248
+ ```bash
249
+ billingo utils convert-id 12345 --format json
250
+ ```
251
+
252
+ ## Complete Invoice Workflow Example
253
+
254
+ Here's a complete workflow an agent might execute:
255
+
256
+ ```bash
257
+ # 1. Check organization setup
258
+ billingo organization get --format json > org.json
259
+
260
+ # 2. List available document blocks (invoice pads)
261
+ billingo document-blocks list --format json > blocks.json
262
+
263
+ # 3. Get or create partner
264
+ billingo partners list --format json > partners.json
265
+ # If partner doesn't exist, create:
266
+ billingo partners create --file new-partner.json --format json
267
+
268
+ # 4. Prepare invoice data with correct IDs
269
+ cat > invoice.json << 'EOF'
270
+ {
271
+ "vendor_id": 1,
272
+ "partner_id": 456,
273
+ "block_id": 1,
274
+ "type": "invoice",
275
+ "fulfillment_date": "2024-01-15",
276
+ "due_date": "2024-01-30",
277
+ "payment_method": "transfer",
278
+ "language": "hu",
279
+ "currency": "HUF",
280
+ "items": [
281
+ {
282
+ "name": "Web Development",
283
+ "unit_price": 50000,
284
+ "quantity": 10,
285
+ "unit": "hour",
286
+ "vat": "27%"
287
+ }
288
+ ]
289
+ }
290
+ EOF
291
+
292
+ # 5. Create invoice
293
+ billingo documents create --file invoice.json --format json > created-invoice.json
294
+
295
+ # 6. Get document ID
296
+ DOC_ID=$(jq -r '.id' created-invoice.json)
297
+
298
+ # 7. Download PDF
299
+ billingo documents download "$DOC_ID" --output "invoice-$DOC_ID.pdf"
300
+
301
+ # 8. Send to customer
302
+ billingo documents send "$DOC_ID" --emails "customer@example.com"
303
+
304
+ # 9. Get public URL for customer portal
305
+ billingo documents public-url "$DOC_ID" --format json
306
+ ```
307
+
308
+ ## Field Validation Tips
309
+
310
+ ### Required Fields by Resource
311
+
312
+ **Partner (Minimum):**
313
+ - `name` (string)
314
+ - `address.country_code` (string, ISO 3166-1 alpha-2)
315
+ - `emails` (array of strings) OR `phone` (string)
316
+
317
+ **Document (Invoice):**
318
+ - `vendor_id` (integer) - Your organization ID
319
+ - `partner_id` (integer) - Customer ID
320
+ - `block_id` (integer) - Document block/pad ID
321
+ - `type` (string) - "invoice", "proforma", etc.
322
+ - `fulfillment_date` (date, YYYY-MM-DD)
323
+ - `due_date` (date, YYYY-MM-DD)
324
+ - `payment_method` (string) - "transfer", "cash", "card", etc.
325
+ - `language` (string) - "hu", "en", "de", etc.
326
+ - `currency` (string) - ISO 4217 code
327
+ - `items` (array) - At least one item
328
+
329
+ **Product:**
330
+ - `name` (string)
331
+ - `unit_price` (number)
332
+ - `unit` (string) - "piece", "hour", etc.
333
+ - `vat` (string) - "27%", "18%", "5%", "0%", "EU", "TAM", etc.
334
+
335
+ ### Common Hungarian VAT Rates
336
+
337
+ - `27%` - Standard rate
338
+ - `18%` - Reduced rate (some foods, accommodation)
339
+ - `5%` - Super-reduced rate (medicines, books)
340
+ - `0%` - Zero-rated
341
+ - `EU` - Intra-EU supply
342
+ - `TAM` - Reverse charge (buyer pays VAT)
343
+ - `AAM` - Special case
344
+ - `FAD` - Agricultural products
345
+
346
+ ### Date Formats
347
+
348
+ All dates must be in `YYYY-MM-DD` format:
349
+ - `2024-01-15` ✓
350
+ - `01/15/2024` ✗
351
+ - `15.01.2024` ✗
352
+
353
+ ## Currency Support
354
+
355
+ Supported currencies (ISO 4217):
356
+ ```
357
+ HUF, EUR, USD, GBP, CHF, AUD, CAD, DKK, NOK, SEK,
358
+ CZK, PLN, RON, BGN, HRK, RSD, RUB, UAH, CNY, JPY,
359
+ KRW, INR, BRL, MXN, ZAR, TRY, SGD, NZD, HKD, THB,
360
+ MYR, PHP, IDR, AED, SAR, ILS, EGP
361
+ ```
362
+
363
+ Get conversion rates:
364
+ ```bash
365
+ billingo currencies convert --from HUF --to EUR --format json
366
+ ```
367
+
368
+ ## Payment Methods
369
+
370
+ Common payment methods:
371
+ - `transfer` - Bank transfer
372
+ - `cash` - Cash payment
373
+ - `card` - Card payment
374
+ - `cheque` - Cheque
375
+ - `cod` - Cash on delivery
376
+ - `paypal` - PayPal
377
+ - `other` - Other method
378
+
379
+ ## Document Types
380
+
381
+ - `invoice` - Regular invoice
382
+ - `proforma` - Proforma invoice
383
+ - `advance` - Advance invoice
384
+ - `draft` - Draft document
385
+
386
+ ## Best Practices for Agents
387
+
388
+ 1. **Always use JSON format for parsing**: Add `--format json` to commands when you need to process the output
389
+ 2. **Handle errors gracefully**: Check exit codes and parse error messages
390
+ 3. **Respect rate limits**: Monitor warnings and implement backoff strategies
391
+ 4. **Validate data before creation**: Check required fields match the API spec
392
+ 5. **Store IDs for reference**: Keep track of created resource IDs for subsequent operations
393
+ 6. **Use file-based input for complex data**: It's more reliable than inline JSON for large payloads
394
+ 7. **Test with list commands first**: Before creating resources, list existing ones to understand the data structure
395
+ 8. **Download invoices after creation**: Always download PDFs and store them securely
396
+
397
+ ## Debugging Tips
398
+
399
+ ### Enable Verbose Output
400
+
401
+ For debugging, you can inspect the full API response:
402
+
403
+ ```bash
404
+ billingo documents get 789 --format json | jq '.'
405
+ ```
406
+
407
+ ### Check Configuration
408
+
409
+ ```bash
410
+ billingo config list
411
+ ```
412
+
413
+ ### Test API Connection
414
+
415
+ ```bash
416
+ billingo organization get
417
+ ```
418
+
419
+ If this works, your API key is valid and the connection is working.
420
+
421
+ ## API Rate Limits
422
+
423
+ The Billingo API has rate limits (typically 60 requests per minute). The CLI:
424
+ - Shows warnings when you're close to the limit
425
+ - Includes rate limit info in response headers
426
+ - Provides clear error messages when rate limited
427
+
428
+ Monitor your usage and implement delays between batch operations.
429
+
430
+ ## Security Notes
431
+
432
+ - Never log or expose API keys in plain text
433
+ - Store API keys securely using the config system or environment variables
434
+ - Don't commit API keys to version control
435
+ - Use read-only API keys when possible (if Billingo supports different permission levels)
436
+
437
+ ## Getting Help
438
+
439
+ For any command, use `--help`:
440
+
441
+ ```bash
442
+ billingo --help
443
+ billingo documents --help
444
+ billingo documents create --help
445
+ ```
446
+
447
+ This provides up-to-date information about available options and usage.