curl https://api.dynamicdocumentapi.com/v1/pdf/from-template \
-H "Authorization: Bearer $DYNAMIC_DOCUMENT_API_KEY" \
-H "Idempotency-Key: INV-2026-0042" \
-H "Content-Type: application/json" \
-d '{
"template_id": "tpl_invoice",
"data": {
"number": "INV-2026-0042",
"issued": "2026-09-22",
"due": "2026-10-22",
"locale": "en-US",
"currency": "USD",
"customer": { "name": "Acme Co.", "address": "1 Main St, Austin, TX" },
"items": [
{ "name": "Pro plan (annual)", "qty": 1, "unit": 1200.00, "total": 1200.00 },
{ "name": "Extra seats", "qty": 4, "unit": 40.00, "total": 160.00 }
],
"subtotal": 1360.00, "tax_rate": 0.08, "tax": 108.80, "total": 1468.80,
"pay_url": "https://pay.example.com/i/INV-2026-0042"
},
"filename": "{{ data.number }}.pdf",
"delivery": "binary"
}' \
--output INV-2026-0042.pdf
// Node.js 18+: render the invoice and return the PDF bytes
export async function renderInvoice(invoice) {
const res = await fetch("https://api.dynamicdocumentapi.com/v1/pdf/from-template", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.DYNAMIC_DOCUMENT_API_KEY}`,
"Idempotency-Key": invoice.number, // safe to retry
"Content-Type": "application/json",
},
body: JSON.stringify({
template_id: "tpl_invoice",
data: invoice,
filename: `${invoice.number}.pdf`,
delivery: "binary",
}),
});
if (!res.ok) throw new Error(await res.text());
return Buffer.from(await res.arrayBuffer());
}
import os
import requests
def render_invoice(invoice: dict) -> bytes:
res = requests.post(
"https://api.dynamicdocumentapi.com/v1/pdf/from-template",
headers={
"Authorization": f"Bearer {os.environ['DYNAMIC_DOCUMENT_API_KEY']}",
"Idempotency-Key": invoice["number"], # safe to retry
},
json={
"template_id": "tpl_invoice",
"data": invoice,
"filename": f"{invoice['number']}.pdf",
"delivery": "binary",
},
timeout=60,
)
res.raise_for_status()
return res.content
<?php
function renderInvoice(array $invoice): string
{
$ch = curl_init('https://api.dynamicdocumentapi.com/v1/pdf/from-template');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('DYNAMIC_DOCUMENT_API_KEY'),
'Idempotency-Key: ' . $invoice['number'], // safe to retry
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'template_id' => 'tpl_invoice',
'data' => $invoice,
'filename' => $invoice['number'] . '.pdf',
'delivery' => 'binary',
]),
]);
return curl_exec($ch); // PDF bytes
}