Automating document generation saves time and keeps branding consistent. Here’s a practical way to produce invoices and similar documents with the DoCreate API.
Use case: invoice generation
When an order is completed in your system, call the DoCreate API with the order data. Your template can include company logo, line items, totals, and a QR code for payment.
Example: Node.js
const response = await fetch('https://api.docreate.example/v1/generate', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.DOCREATE_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
templateId: 'tmpl_invoice',
data: {
invoice_number: order.id,
customer_name: order.customerName,
items: order.lineItems,
total: order.total,
due_date: order.dueDate,
},
}),
});
const { pdfUrl } = await response.json();
// Attach pdfUrl to email or store for download
Example: Python
import os
import requests
resp = requests.post(
"https://api.docreate.example/v1/generate",
headers={"Authorization": f"Bearer {os.environ['DOCREATE_API_KEY']}"},
json={
"templateId": "tmpl_invoice",
"data": {
"invoice_number": order_id,
"customer_name": customer_name,
"items": line_items,
"total": total,
"due_date": due_date,
},
},
)
pdf_url = resp.json()["pdfUrl"]
Tips
- Use webhooks to get notified when a PDF is ready if you use async generation.
- Store template IDs and variable names in config so non-developers can adjust templates without code changes.
- For high volume, use batch endpoints and rate limits described in the API reference.
With a single template and a small integration, you can automate invoices, quotes, and other recurring documents across your stack.
