תיעוד API
מחולל החשבוניות מספק API בסגנון REST ליצירת חשבוניות וקבלות בפורמט PDF.
כתובת בסיס
http://localhost:3000/api
Features
- Generate PDF invoices and receipts
- Multiple template types (receipt, tax invoice, exempt business receipt)
- Custom business branding
- Handlebars template engine
- Rate limiting for API protection
- n8n workflow integration
אימות
כעת ה־API אינו דורש אימות. בסביבות פרודקשן מומלץ להוסיף אימות מפתח API או מנגנוני אבטחה אחרים.
Rate Limiting: The API is rate-limited to 100 requests per 15 minutes per IP address.
נקודות קצה
POST /api/generate-pdf
יצירת חשבונית/קבלה כקובץ PDF.
גוף בקשה
{
"templateType": "receipt",
"customer": {
"name": "John Doe",
"address": "123 Main St",
"city": "City",
"state": "State",
"postalCode": "12345",
"email": "john@example.com",
"phone": "+1-555-123-4567"
},
"business": {
"name": "Your Business",
"address": "456 Business Ave",
"city": "Business City",
"state": "State",
"postalCode": "67890",
"phone": "+1-555-987-6543",
"email": "info@business.com",
"website": "www.business.com",
"abn": "12345678901"
},
"items": [
{
"description": "Product or Service",
"quantity": 2,
"rate": 50.00,
"amount": 100.00
}
],
"subtotal": 100.00,
"taxRate": 10,
"taxAmount": 10.00,
"total": 110.00,
"currency": "$",
"paymentTerms": "30 days",
"paymentMethod": "Bank Transfer",
"notes": "Thank you for your business!"
}
שדות חובה
templateType- Template to use (receipt, tax_invoice, exempt_business_receipt)customer.name- Customer nameitems- Array of invoice items (minimum 1 item)
תגובה
מחזיר קובץ PDF עם כותרות מתאימות להורדה.
GET /api/templates
קבלת רשימת תבניות זמינות.
תגובה
{
"success": true,
"templates": [
"receipt",
"tax_invoice",
"exempt_business_receipt"
]
}
POST /api/preview
תצוגה מקדימה של התבנית כ־HTML (יעיל לניפוי באגים ופיתוח תבניות).
גוף בקשה
זהה ל־generate-pdf אך מחזיר HTML במקום PDF.
Response
Returns rendered HTML content with Content-Type: text/html.
GET /api/health
נקודת קצה לבדיקת תקינות וזמינות השירות.
תגובה
{
"success": true,
"status": "OK",
"timestamp": "2024-01-15T10:30:00.000Z",
"service": "Invoice PDF Generator"
}
Examples
cURL Example
curl -X POST http://localhost:3000/api/generate-pdf \
-H "Content-Type: application/json" \
-d '{
"templateType": "receipt",
"customer": {
"name": "John Doe",
"email": "john@example.com"
},
"items": [{
"description": "Consulting Service",
"quantity": 1,
"rate": 150.00,
"amount": 150.00
}],
"total": 150.00
}' \
--output invoice.pdf
n8n Workflow Example
Use the HTTP Request node in n8n:
- Method: POST
- URL: http://localhost:3000/api/generate-pdf
- Body: JSON with invoice data
- Response Format: File
Error Codes
| Code | Status | Description |
|---|---|---|
| 400 | Bad Request | Missing required fields or invalid data |
| 404 | Not Found | Template not found or endpoint doesn't exist |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | PDF generation failed or server error |