Generate invoice PDFs from JSON
Keep the invoice layout in Platendoc and the customer data in your application. This example turns an invoice number, customer name, and total into a downloadable PDF.
Create an invoice template
In the template editor, paste this HTML into Code mode, save it, and copy the template ID. The Liquid fields in double braces match the variable names in the request.
<h1>Invoice {{ invoice_number }}</h1>
<p>Bill to: {{ customer }}</p>
<p>Total due: {{ amount }}</p>Send the invoice data
Create an API key in the same workspace with generations:trigger and generations:read permissions. Set PLATENDOC_API_KEY in your shell and replace YOUR_SAVED_TEMPLATE_ID with the ID you copied. Send one request per invoice.
curl https://api.platendoc.com/v1/generations \
-H "Authorization: Bearer $PLATENDOC_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"templateId": "YOUR_SAVED_TEMPLATE_ID",
"format": "pdf",
"variables": {
"invoice_number": "INV-1042",
"customer": "Acme Studio",
"amount": "$125.00"
}
}'Download the finished PDF
A successful submission returns 202 Accepted. Set GENERATION_ID to the response’s id, then request its status.
curl "https://api.platendoc.com/v1/generations/$GENERATION_ID" \
-H "Authorization: Bearer $PLATENDOC_API_KEY"While the status is PENDING or PROCESSING, wait a few seconds before checking again. When it is COMPLETED, download the invoice from outputUrl. The signed link lasts one hour. Fetch the completed generation again for a fresh link. If the status is FAILED, inspect the generation error before submitting another request.
To receive a notification when a generation finishes, configure a generation webhook.