Generate professional PDF documents from JSON using the Kagyz API. Each script demonstrates a different document type.
git clone https://github.com/kagyz/node-example.git
cd node-example
npm install
cp .env.example .envAdd your API key to .env:
KAGYZ_API_KEY=your_api_key_here
Get your API key at kagyz.com.
| Script | Command | Description |
|---|---|---|
invoice.js |
npm run invoice |
Standard invoice with tax |
receipt.js |
npm run receipt |
Payment receipt with transaction ID |
quote.js |
npm run quote |
Quote / estimate with expiry date |
credit-note.js |
npm run credit-note |
Credit note referencing an invoice |
packing-slip.js |
npm run packing-slip |
Packing slip with SKUs and weights |
timesheet.js |
npm run timesheet |
Timesheet invoice with hourly billing |
arabic-invoice.js |
npm run arabic |
RTL Arabic invoice (SAR currency) |
branded-invoice.js |
npm run branded |
Invoice with custom accent color |
email-invoice.js |
npm run email |
Generate invoice and send via email |
Add deliver_to to any request to email the PDF as an attachment:
deliver_to: {
email: 'client@example.com',
subject: 'Invoice INV-001 from Acme Corp', // optional, auto-generated if omitted
message: 'Please find your invoice attached.' // optional, auto-generated if omitted
}The PDF is still returned in the response. The X-Kagyz-Delivered-To header confirms delivery.
Note: from.email is required when using email delivery.
You can override the accent color per-request using the branding field:
branding: {
accent_color: '#22c55e'
}To add your company logo, upload it via the Kagyz Dashboard. The logo will appear on all generated documents automatically.
Each script sends a JSON payload to the Kagyz API and saves the returned PDF:
const response = await fetch('https://api.kagyz.com/v1/invoice', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.KAGYZ_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
invoice_number: 'INV-001',
currency: 'USD',
// ... your data
})
});
fs.writeFileSync('invoice.pdf', Buffer.from(await response.arrayBuffer()));- Node.js 18+
- A Kagyz API key
MIT