### Create Invoice (Node.js)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
A basic example demonstrating how to create an invoice using EasyInvoice in a Node.js environment. Ensure you have the library installed.
```javascript
// Import the library into your project
var easyinvoice = require('easyinvoice');
// Create your invoice! Easy!
var data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
products: [
{
quantity: 2,
description: "Test product",
taxRate: 6,
price: 33.87
}
]
};
easyinvoice.createInvoice(data, function (result) {
// The response will contain a base64 encoded PDF file
console.log('PDF base64 string: ', result.pdf);
// Now this result can be used to save, download or render your invoice
// Please review the documentation below on how to do this
});
```
--------------------------------
### Direct REST API Access Example
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
This example shows how to make a direct HTTPS POST request to the EasyInvoice API for invoice creation. Ensure your package version supports apiKey for paid plans.
```shell
# HTTPS POST
https://api.budgetinvoice.com/v2/free/invoices
```
--------------------------------
### Install Easy Invoice via Package Manager
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Use these commands to add the easyinvoice package to your project dependencies.
```bash
$ npm install easyinvoice
```
```bash
$ yarn add easyinvoice
```
```bash
$ pnpm install easyinvoice
```
--------------------------------
### Create Invoice (Web)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
A basic example demonstrating how to create an invoice using EasyInvoice in a web browser. Include the script tag in your HTML.
```html
// Import the library into your project
```
--------------------------------
### Asynchronous Invoice Creation (High Volume)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Demonstrates creating multiple invoices concurrently using async/await and Promise.all for high-volume scenarios. This approach improves performance by processing requests in parallel.
```javascript
// Import the library into your project
var easyinvoice = require('easyinvoice');
// Create a promises array to store all your promises
const promises = [];
// Use a loop to prepare all your invoices for async creation
for (let i = 0; i < 25; i++) {
// Add your invoice data to the promise array
promises[i] = easyinvoice.createInvoice({
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
});
}
// Create all your invoices at the same time
const invoices = await Promise.all(promises);
```
--------------------------------
### Asynchronous Invoice Creation
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Demonstrates how to create multiple invoices concurrently using Promises and async/await for high-volume scenarios.
```APIDOC
## Asynchronous Invoice Creation
### Description
This section details how to efficiently create a large number of invoices simultaneously by leveraging asynchronous operations with Promises and async/await.
### Method
POST (implicitly via `easyinvoice.createInvoice` calls)
### Endpoint
/createInvoice (implicitly)
### Parameters
(Refer to the POST /createInvoice endpoint for data structure)
### Request Example (NodeJS)
```javascript
// Import the library into your project
var easyinvoice = require('easyinvoice');
// Create a promises array to store all your promises
const promises = [];
// Use a loop to prepare all your invoices for async creation
for (let i = 0; i < 25; i++) {
// Add your invoice data to the promise array
promises[i] = easyinvoice.createInvoice({
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
});
}
// Create all your invoices at the same time
const invoices = await Promise.all(promises);
// 'invoices' will be an array of results, each containing a base64 encoded PDF
console.log(`Successfully created ${invoices.length} invoices.`);
```
### Response
#### Success Response (200)
- **invoices** (array) - An array where each element is the result of a single invoice creation (containing a base64 encoded PDF).
#### Response Example
```json
[
{
"pdf": "JVBERi0xLjQKJc..."
},
{
"pdf": "JVBERi0xLjQKJc..."
}
// ... more invoice results
]
```
```
--------------------------------
### Configure locale and currency with Node.js
Source: https://context7.com/dashweb-bv/easyinvoice/llms.txt
Demonstrates how to format invoices for different regions using the easyinvoice library. The locale and currency settings determine the output formatting of numbers and symbols.
```javascript
const easyinvoice = require('easyinvoice');
// German formatting: 1.234,56 €
const germanInvoice = await easyinvoice.createInvoice({
apiKey: "free",
mode: "development",
settings: {
locale: "de-DE",
currency: "EUR"
},
products: [{ quantity: 1, description: "German Service", taxRate: 19, price: 1234.56 }]
});
// US formatting: $1,234.56
const usInvoice = await easyinvoice.createInvoice({
apiKey: "free",
mode: "development",
settings: {
locale: "en-US",
currency: "USD"
},
products: [{ quantity: 1, description: "US Service", taxRate: 8.25, price: 1234.56 }]
});
// Japanese formatting: ¥1,235
const japaneseInvoice = await easyinvoice.createInvoice({
apiKey: "free",
mode: "development",
settings: {
locale: "ja-JP",
currency: "JPY"
},
products: [{ quantity: 1, description: "日本サービス", taxRate: 10, price: 123456 }]
});
// British formatting: £1,234.56
const ukInvoice = await easyinvoice.createInvoice({
apiKey: "free",
mode: "development",
settings: {
locale: "en-GB",
currency: "GBP"
},
products: [{ quantity: 1, description: "UK Service", taxRate: 20, price: 1234.56 }]
});
console.log('Invoices created with different locales and currencies');
```
--------------------------------
### Import EasyInvoice (ES6)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Use this to import the EasyInvoice library in an ES6 environment.
```javascript
import easyinvoice from 'easyinvoice';
```
--------------------------------
### Import EasyInvoice (CommonJS)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Use this to import the EasyInvoice library in a CommonJS environment.
```javascript
var easyinvoice = require('easyinvoice');
```
--------------------------------
### Create Invoice with Async/Await (NodeJS)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Generates an invoice using async/await. The result contains a base64 encoded PDF string. Ensure the library is imported.
```javascript
// Import the library into your project
var easyinvoice = require('easyinvoice');
// Create your invoice! Easy!
var data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
};
const result = await easyinvoice.createInvoice(data);
// The response will contain a base64 encoded PDF file
console.log('PDF base64 string: ', result.pdf);
```
--------------------------------
### Locale and Currency Configuration
Source: https://context7.com/dashweb-bv/easyinvoice/llms.txt
Configure number formatting and currency symbols based on different regional settings using the `createInvoice` method with specified `locale` and `currency` options.
```APIDOC
## Locale and Currency Configuration
### Description
Configure number formatting and currency symbols based on different regional settings. The library uses the ECMAScript Internationalization API for proper formatting.
### Method
JavaScript (Node.js)
### Endpoint
N/A (Client-side or Server-side JavaScript function)
### Request Example
```javascript
const easyinvoice = require('easyinvoice');
// German formatting: 1.234,56 €
const germanInvoice = await easyinvoice.createInvoice({
apiKey: "free",
mode: "development",
settings: {
locale: "de-DE",
currency: "EUR"
},
products: [{ quantity: 1, description: "German Service", taxRate: 19, price: 1234.56 }]
});
// US formatting: $1,234.56
const usInvoice = await easyinvoice.createInvoice({
apiKey: "free",
mode: "development",
settings: {
locale: "en-US",
currency: "USD"
},
products: [{ quantity: 1, description: "US Service", taxRate: 8.25, price: 1234.56 }]
});
// Japanese formatting: ¥1,235
const japaneseInvoice = await easyinvoice.createInvoice({
apiKey: "free",
mode: "development",
settings: {
locale: "ja-JP",
currency: "JPY"
},
products: [{ quantity: 1, description: "日本サービス", taxRate: 10, price: 123456 }]
});
// British formatting: £1,234.56
const ukInvoice = await easyinvoice.createInvoice({
apiKey: "free",
mode: "development",
settings: {
locale: "en-GB",
currency: "GBP"
},
products: [{ quantity: 1, description: "UK Service", taxRate: 20, price: 1234.56 }]
});
console.log('Invoices created with different locales and currencies');
```
```
--------------------------------
### Include Logo and Background via URL
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Specify image sources for the logo and background using direct URLs. Ensure the URLs point to publicly accessible image files.
```javascript
const data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
images: {
logo: "https://public.budgetinvoice.com/img/logo_en_original.png",
background: "https://public.budgetinvoice.com/img/watermark_draft.jpg",
}
};
```
--------------------------------
### Create an invoice via REST API
Source: https://context7.com/dashweb-bv/easyinvoice/llms.txt
Sends a POST request to the BudgetInvoice API to generate an invoice. Requires a valid API key in the Authorization header.
```bash
curl -X POST https://api.budgetinvoice.com/v2/free/invoices \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"data": {
"mode": "development",
"sender": {
"company": "Curl Corp",
"address": "Terminal Way 1",
"city": "Shell City",
"country": "USA"
},
"client": {
"company": "HTTP Client Inc",
"address": "Request Road 200",
"city": "Response Town",
"country": "USA"
},
"information": {
"number": "API-2024-001",
"date": "2024-01-30",
"dueDate": "2024-02-28"
},
"products": [
{
"quantity": 100,
"description": "API Requests",
"taxRate": 0,
"price": 0.01
},
{
"quantity": 1,
"description": "Monthly Subscription",
"taxRate": 10,
"price": 29.99
}
],
"settings": {
"currency": "USD",
"locale": "en-US"
},
"bottomNotice": "Thank you for using our API!"
}
}'
```
--------------------------------
### Create PDF Invoice with Easy Invoice
Source: https://context7.com/dashweb-bv/easyinvoice/llms.txt
Generates a PDF invoice using the `createInvoice` method. Configure sender, client, products, and settings. Supports free or paid API keys and development/production modes. Use async/await for modern JavaScript or callbacks for older environments.
```javascript
const easyinvoice = require('easyinvoice');
// Complete invoice creation with all options
const data = {
apiKey: "free", // Use "free" for free tier or your paid API key
mode: "development", // "development" for testing, "production" for live
images: {
logo: "https://public.budgetinvoice.com/img/logo_en_original.png",
background: "https://public.budgetinvoice.com/img/watermark-draft.jpg"
},
sender: {
company: "Sample Corp",
address: "Sample Street 123",
zip: "1234 AB",
city: "Sampletown",
country: "Samplecountry",
custom1: "VAT: 123456789",
custom2: "IBAN: NL00BANK0123456789"
},
client: {
company: "Client Corp",
address: "Clientstreet 456",
zip: "4567 CD",
city: "Clientcity",
country: "Clientcountry"
},
information: {
number: "2024.0001",
date: "15-01-2024",
dueDate: "31-01-2024"
},
products: [
{
quantity: 2,
description: "Web Development Services",
taxRate: 21,
price: 150.00
},
{
quantity: 5,
description: "Consulting Hours",
taxRate: 21,
price: 85.50
},
{
quantity: 1,
description: "Domain Registration",
taxRate: 6,
price: 15.00
}
],
bottomNotice: "Kindly pay your invoice within 15 days.",
settings: {
currency: "EUR",
locale: "nl-NL",
marginTop: 25,
marginRight: 25,
marginLeft: 25,
marginBottom: 25,
format: "A4",
orientation: "portrait"
},
translate: {
invoice: "FACTUUR",
number: "Nummer",
date: "Datum",
dueDate: "Vervaldatum",
subtotal: "Subtotaal",
products: "Producten",
quantity: "Aantal",
price: "Prijs",
productTotal: "Totaal",
total: "Totaal",
taxNotation: "btw"
}
};
// Using async/await
try {
const result = await easyinvoice.createInvoice(data);
console.log('PDF base64 string:', result.pdf);
console.log('Calculations:', result.calculations);
// result.calculations contains: { products: [...], tax: {...}, subtotal: 742.5, total: 898.43 }
} catch (error) {
console.error('Invoice creation failed:', error.message);
}
// Using callback pattern
easyinvoice.createInvoice(data, function(result) {
console.log('PDF base64 string:', result.pdf);
});
```
--------------------------------
### Use product placeholders within products tags
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Placeholders for product details must be used inside the tag block.
```html
Within:
%description%
```
```html
Within:
%quantity%
```
```html
Within:
%price%
```
```html
Within:
%row-total%
```
--------------------------------
### Include Easy Invoice via CDN
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Include these script tags in your HTML to load the library directly from a CDN.
```html
```
```html
```
--------------------------------
### Configure Invoice Locale and Currency (Germany)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Set the locale to 'de-DE' and currency to 'EUR' for German formatting, displaying prices with commas for thousands separators and a period for decimals, followed by the Euro symbol.
```javascript
//E.g. for Germany, prices would look like 123.456,78 €
const data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
settings: {
locale: 'de-DE',
currency: 'EUR'
}
};
```
--------------------------------
### Decode and save the PDF (Linux/Mac)
Source: https://context7.com/dashweb-bv/easyinvoice/llms.txt
This command demonstrates how to pipe the PDF data from the invoice creation API response to `jq` to extract the base64 encoded PDF, then decode it using `base64 -d` and save it as an invoice.pdf file.
```APIDOC
## Decode and save the PDF (Linux/Mac)
### Description
This command extracts the base64 encoded PDF from the API response, decodes it, and saves it as a PDF file.
### Method
POST
### Endpoint
https://api.budgetinvoice.com/v2/free/invoices
### Request Example
```bash
curl -X POST https://api.budgetinvoice.com/v2/free/invoices \
-H "Content-Type: application/json" \
-d '{"data": {"mode": "development", "products": [{"quantity": 1, "description": "Test", "price": 100}]}}' \
| jq -r '.data.pdf' | base64 -d > invoice.pdf
```
```
--------------------------------
### Create Invoice with Async/Await Error Handling
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
This approach uses async/await for creating an invoice, providing a cleaner way to handle asynchronous operations and errors. A try-catch block is essential for error management.
```javascript
var easyinvoice = require('easyinvoice');
var data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
};
try {
const invoice = await easyinvoice.createInvoice(data);
console.log(invoice);
} catch (error) {
// Handle the error
console.log(error);
}
```
--------------------------------
### Configure Invoice Locale and Currency (US)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Configure the locale to 'en-US' and currency to 'USD' for United States formatting, which uses commas for thousands separators and periods for decimals, preceded by the dollar sign.
```javascript
//E.g. for US, prices would look like $123,456.78
const data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
settings: {
locale: 'en-US',
currency: 'USD'
}
};
```
--------------------------------
### Create Invoice with Callback Error Handling
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Use this method to create an invoice and handle potential errors using a callback function. Ensure you have registered for a production API key if not in development mode.
```javascript
var easyinvoice = require('easyinvoice');
var data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
};
easyinvoice.createInvoice(data, function (invoice) {
console.log(invoice);
}).catch((error) => {
// Handle the error
console.log(error);
});
```
--------------------------------
### Generate Invoice with EasyInvoice in NodeJS
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Configures invoice data including sender, client, products, and settings, then generates a base64 encoded PDF.
```javascript
//Import the library into your project
var easyinvoice = require('easyinvoice');
var data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
images: {
// The logo on top of your invoice
logo: "https://public.budgetinvoice.com/img/logo_en_original.png",
// The invoice background
background: "https://public.budgetinvoice.com/img/watermark-draft.jpg"
},
// Your own data
sender: {
company: "Sample Corp",
address: "Sample Street 123",
zip: "1234 AB",
city: "Sampletown",
country: "Samplecountry"
// custom1: "custom value 1",
// custom2: "custom value 2",
// custom3: "custom value 3"
},
// Your recipient
client: {
company: "Client Corp",
address: "Clientstreet 456",
zip: "4567 CD",
city: "Clientcity",
country: "Clientcountry"
// custom1: "custom value 1",
// custom2: "custom value 2",
// custom3: "custom value 3"
},
information: {
// Invoice number
number: "2021.0001",
// Invoice data
date: "12-12-2021",
// Invoice due date
dueDate: "31-12-2021"
},
// The products you would like to see on your invoice
// Total values are being calculated automatically
products: [
{
quantity: 2,
description: "Product 1",
taxRate: 6,
price: 33.87
},
{
quantity: 4.1,
description: "Product 2",
taxRate: 6,
price: 12.34
},
{
quantity: 4.5678,
description: "Product 3",
taxRate: 21,
price: 6324.453456
}
],
// The message you would like to display on the bottom of your invoice
bottomNotice: "Kindly pay your invoice within 15 days.",
// Settings to customize your invoice
settings: {
currency: "USD", // See documentation 'Locales and Currency' for more info. Leave empty for no currency.
// locale: "nl-NL", // Defaults to en-US, used for number formatting (See documentation 'Locales and Currency')
// marginTop: 25, // Defaults to '25'
// marginRight: 25, // Defaults to '25'
// marginLeft: 25, // Defaults to '25'
// marginBottom: 25, // Defaults to '25'
// format: "A4", // Defaults to A4, options: A3, A4, A5, Legal, Letter, Tabloid
// height: "1000px", // allowed units: mm, cm, in, px
// width: "500px", // allowed units: mm, cm, in, px
// orientation: "landscape" // portrait or landscape, defaults to portrait
},
// Translate your invoice to your preferred language
translate: {
// invoice: "FACTUUR", // Default to 'INVOICE'
// number: "Nummer", // Defaults to 'Number'
// date: "Datum", // Default to 'Date'
// dueDate: "Verloopdatum", // Defaults to 'Due Date'
// subtotal: "Subtotaal", // Defaults to 'Subtotal'
// products: "Producten", // Defaults to 'Products'
// quantity: "Aantal", // Default to 'Quantity'
// price: "Prijs", // Defaults to 'Price'
// productTotal: "Totaal", // Defaults to 'Total'
// total: "Totaal", // Defaults to 'Total'
// taxNotation: "btw" // Defaults to 'vat'
},
// Customize enables you to provide your own templates
// Please review the documentation for instructions and examples
// "customize": {
// "template": fs.readFileSync('template.html', 'base64') // Must be base64 encoded html
// }
};
//Create your invoice! Easy!
easyinvoice.createInvoice(data, function (result) {
//The response will contain a base64 encoded PDF file
console.log('PDF base64 string: ', result.pdf);
});
```
--------------------------------
### Read Local File as Base64 (NodeJS)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Use this code to read local image files (logo, background) as base64 strings for inclusion in invoices. Requires the 'fs' module.
```javascript
//Import fs to be able to read from the local file system
var fs = require("fs");
//Use the code below to read your local file as a base64 string
const data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
images: {
logo: fs.readFileSync('logo.png', 'base64'),
background: fs.readFileSync('images/background.png', 'base64')
}
};
```
--------------------------------
### POST /v2/free/invoices
Source: https://context7.com/dashweb-bv/easyinvoice/llms.txt
Create a basic invoice using curl and receive a base64 encoded PDF. This endpoint is suitable for generating invoices with detailed sender, client, information, products, and settings.
```APIDOC
## POST /v2/free/invoices
### Description
Creates an invoice with the provided data and returns a base64 encoded PDF of the invoice.
### Method
POST
### Endpoint
https://api.budgetinvoice.com/v2/free/invoices
### Parameters
#### Headers
- **Content-Type** (string) - Required - application/json
- **Authorization** (string) - Required - Bearer your-api-key
#### Request Body
- **data** (object) - Required - The invoice data object.
- **mode** (string) - Optional - 'development' or 'production'.
- **sender** (object) - Required - Sender details.
- **company** (string) - Required
- **address** (string) - Required
- **city** (string) - Required
- **country** (string) - Required
- **client** (object) - Required - Client details.
- **company** (string) - Required
- **address** (string) - Required
- **city** (string) - Required
- **country** (string) - Required
- **information** (object) - Required - Invoice information.
- **number** (string) - Required
- **date** (string) - Required (YYYY-MM-DD)
- **dueDate** (string) - Required (YYYY-MM-DD)
- **products** (array) - Required - Array of product objects.
- **quantity** (number) - Required
- **description** (string) - Required
- **taxRate** (number) - Required
- **price** (number) - Required
- **settings** (object) - Optional - Invoice settings.
- **currency** (string) - Optional - e.g., 'USD'
- **locale** (string) - Optional - e.g., 'en-US'
- **bottomNotice** (string) - Optional - Text to display at the bottom of the invoice.
### Request Example
```json
{
"data": {
"mode": "development",
"sender": {
"company": "Curl Corp",
"address": "Terminal Way 1",
"city": "Shell City",
"country": "USA"
},
"client": {
"company": "HTTP Client Inc",
"address": "Request Road 200",
"city": "Response Town",
"country": "USA"
},
"information": {
"number": "API-2024-001",
"date": "2024-01-30",
"dueDate": "2024-02-28"
},
"products": [
{
"quantity": 100,
"description": "API Requests",
"taxRate": 0,
"price": 0.01
},
{
"quantity": 1,
"description": "Monthly Subscription",
"taxRate": 10,
"price": 29.99
}
],
"settings": {
"currency": "USD",
"locale": "en-US"
},
"bottomNotice": "Thank you for using our API!"
}
}
```
### Response
#### Success Response (200)
- **data** (object) - Contains the PDF and calculation details.
- **pdf** (string) - Base64 encoded PDF of the invoice.
- **calculations** (object) - Calculation breakdown.
- **products** (array) - Details of product calculations.
- **tax** (object) - Tax breakdown by rate.
- **subtotal** (number) - Subtotal amount.
- **total** (number) - Total amount.
#### Response Example
```json
{
"data": {
"pdf": "JVBERi0xLjcKCjEgMCBvYmoKPDwKL1...",
"calculations": {
"products": [...],
"tax": { "0": 0, "10": 3.00 },
"subtotal": 30.99,
"total": 33.99
}
}
}
```
```
--------------------------------
### Create Custom Invoice with HTML Template
Source: https://context7.com/dashweb-bv/easyinvoice/llms.txt
Uses a base64-encoded HTML string as a template for invoice generation. Requires the easyinvoice npm package and fs module for file operations.
```javascript
const easyinvoice = require('easyinvoice');
const fs = require('fs');
// Custom HTML template with placeholders
const customTemplate = `
%document-title%
%number-title%: %number%
%date-title%: %date%
%due-date-title%: %due-date%
From:
%company-from%
%address-from%
%zip-from% %city-from%
%country-from%
To:
%company-to%
%address-to%
%zip-to% %city-to%
%country-to%
%products-header-products%
%products-header-quantity%
%products-header-price%
%products-header-total%
%description%
%quantity%
%price%
%row-total%
%subtotal-title%:
%subtotal%
%tax-notation% %tax-rate%%:
%tax%
Total:
%total%
%bottom-notice%
`;
async function createCustomInvoice() {
const data = {
apiKey: "free",
mode: "development",
customize: {
template: Buffer.from(customTemplate).toString('base64')
},
images: { logo: "https://public.budgetinvoice.com/img/logo_en_original.png" },
sender: { company: "Custom Design Co", address: "Creative St 1", zip: "12345", city: "Design City", country: "Netherlands" },
client: { company: "Art Client", address: "Gallery Ave 99", zip: "67890", city: "Art Town", country: "Belgium" },
information: { number: "CUSTOM-001", date: "2024-01-25", dueDate: "2024-02-25" },
products: [
{ quantity: 1, description: "Custom Logo Design", taxRate: 21, price: 500 },
{ quantity: 3, description: "Brand Consultation (hours)", taxRate: 21, price: 150 }
],
bottomNotice: "Custom invoices created with Easy Invoice!",
settings: { currency: "EUR", locale: "nl-NL" }
};
const result = await easyinvoice.createInvoice(data);
fs.writeFileSync('custom-invoice.pdf', result.pdf, 'base64');
console.log('Custom invoice created successfully!');
}
createCustomInvoice();
```
--------------------------------
### Include Logo and Background via Base64
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Embed images for the logo and background directly within the data object using their Base64 encoded string representations. A sample Base64 string is provided as a placeholder.
```javascript
const data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
//Note: Sample base64 string
//Please use the link below to convert your image to base64
images: {
logo: "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
background: "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
}
};
```
--------------------------------
### High Volume Asynchronous Invoice Creation
Source: https://context7.com/dashweb-bv/easyinvoice/llms.txt
Use Promise.all to generate multiple invoices concurrently, maximizing throughput for bulk invoice creation. Ensure your API key and invoice data are correctly formatted.
```javascript
const easyinvoice = require('easyinvoice');
// Create multiple invoices asynchronously
async function generateBulkInvoices(invoiceDataArray) {
const promises = invoiceDataArray.map((invoiceData, index) => {
return easyinvoice.createInvoice({
apiKey: "your-api-key",
mode: "production",
information: {
number: `2024.${String(index + 1).padStart(4, '0')}`,
date: new Date().toLocaleDateString('en-GB'),
dueDate: new Date(Date.now() + 30*24*60*60*1000).toLocaleDateString('en-GB')
},
sender: invoiceData.sender,
client: invoiceData.client,
products: invoiceData.products,
settings: { currency: "USD", locale: "en-US" }
});
});
try {
const invoices = await Promise.all(promises);
console.log(`Successfully generated ${invoices.length} invoices`);
return invoices;
} catch (error) {
console.error('Bulk generation failed:', error);
throw error;
}
}
// Example usage with 25 invoices
const clients = Array.from({ length: 25 }, (_, i) => ({
sender: { company: "My Company", address: "123 Main St", city: "New York", country: "USA" },
client: { company: `Client ${i + 1}`, address: `${i + 100} Client Ave`, city: "Boston", country: "USA" },
products: [{ quantity: 1, description: "Service", taxRate: 8, price: 100 + i }]
}));
const results = await generateBulkInvoices(clients);
```
--------------------------------
### POST /createInvoice
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Creates an invoice using the provided data. The API accepts JSON data and can optionally use a paid API key for enhanced features. Registration is required for a production API key.
```APIDOC
## POST /createInvoice
### Description
Creates an invoice with the provided data. Supports both development and production modes. An API key can be optionally provided in the header.
### Method
POST
### Endpoint
/createInvoice
### Parameters
#### Request Body
- **data** (object) - Required - Parent parameter for invoice details.
- **mode** (string) - Optional - Specifies the mode, either 'development' or 'production'. Defaults to 'production'.
- **products** (array) - Required - An array of product objects.
- **quantity** (number) - Required - The quantity of the product.
- **description** (string) - Required - A description of the product.
- **taxRate** (number) - Required - The tax rate applicable to the product.
- **price** (number) - Required - The price of the product.
### Request Example
```json
{
"data": {
"mode": "development",
"products": [
{
"quantity": 2,
"description": "Test product",
"taxRate": 6,
"price": 33.87
}
]
}
}
```
### Headers
- **Authorization** (string) - Optional - Bearer token for authentication. Example: `Bearer 123abc`
### Response
#### Success Response (200)
- **pdf** (string) - Base64 encoded PDF file of the created invoice.
#### Response Example
```json
{
"pdf": "JVBERi0xLjQKJc..."
}
```
```
--------------------------------
### Print Invoice (Browser)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Prints the generated invoice directly from the browser. Requires the invoice PDF data in base64 format.
```javascript
var data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
};
const result = await easyinvoice.createInvoice(data);
easyinvoice.print(result.pdf);
```
--------------------------------
### Download Invoice (Browser Only)
Source: https://context7.com/dashweb-bv/easyinvoice/llms.txt
Downloads the generated PDF invoice directly to the user's device. This method requires a browser environment and uses the FileSaver library internally. Ensure easyinvoice.min.js is included.
```html
```
--------------------------------
### Customize Invoice Template (Base64)
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Allows providing a custom HTML template for the invoice, which must be base64 encoded. Invoice information can be injected using placeholders.
```javascript
// You are able to provide your own html template
var html = '
Hello world! This is invoice number %number%
';
const data = {
apiKey: "free", // Please register to receive a production apiKey: https://app.budgetinvoice.com/register
mode: "development", // Production or development, defaults to production
customize: {
// btoa === base64 encode
template: btoa(html) // Your template must be base64 encoded
},
information: {
number: '2022.0001'
}
};
// This will return a pdf with the following content
// Hello world! This is invoice number 2022.0001
```
--------------------------------
### Define product rows with products tags
Source: https://github.com/dashweb-bv/easyinvoice/blob/master/README.md
Enclose custom product rows within tags to ensure the template parser can iterate over them.
```html
```
--------------------------------
### Render Invoice in Browser
Source: https://context7.com/dashweb-bv/easyinvoice/llms.txt
Renders a PDF invoice directly into a DOM element. Requires pdfjs-dist and easyinvoice scripts to be loaded.
```html
```