Export a PDF
POST /api/export/{id}/pdf
Renders the template {id} with the variable values you send, and returns the PDF. This is the
endpoint most integrations need — often the only one.
Request
Section titled “Request”| Part | Value |
|---|---|
Path id |
Template ID — the last segment of the editor URL /editor/{id} |
| Header | x-api-key: <your-api-key> |
| Header | Content-Type: application/json |
| Body | A flat JSON object: variable name → value |
{ "client": "ACME Corp", "discount": true, "lines": [ { "label": "A5 flyers", "price": "$85" }, { "label": "A3 posters", "price": "$120" } ], "total": "$205.00"}- Keys are the variable names shown in the editor (case-sensitive).
- Missing or empty variables fall back to their default.
- Keys that match no variable are ignored.
- A template without variables accepts an empty body (
{}).
The value you send depends on the variable’s type — see
Variables. In short: string takes a string (format dates and
amounts yourself), boolean takes true/false, and object-list takes an array of objects.
Response
Section titled “Response”200 OK with the PDF as the body.
| Header | Example |
|---|---|
Content-Type |
application/pdf |
Content-Disposition |
attachment; filename="Tutorial.pdf"; filename*=UTF-8''Tutorial.pdf |
Content-Length |
69136 |
X-Generation-Time |
893 — rendering time in milliseconds |
The file name comes from the template title. The PDF has one page per page of the template, at
the template’s pageSize.
Examples
Section titled “Examples”curl -X POST "https://app.imprime.io/api/export/$TEMPLATE_ID/pdf" \ -H "x-api-key: $IMPRIME_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "client": "ACME Corp", "total": "$205.00" }' \ --fail-with-body -o quote.pdfconst res = await fetch(`https://app.imprime.io/api/export/${templateId}/pdf`, { method: 'POST', headers: { 'x-api-key': process.env.IMPRIME_API_KEY, 'Content-Type': 'application/json', }, body: JSON.stringify({ client: 'ACME Corp', discount: true, lines: [{ label: 'A5 flyers', price: '$85' }], total: '$205.00', }),});
if (!res.ok) { const { code, error } = await res.json(); throw new Error(`[${res.status}] ${code ?? ''} ${error}`);}
const pdf = Buffer.from(await res.arrayBuffer());import os, requests
res = requests.post( f"https://app.imprime.io/api/export/{template_id}/pdf", headers={"x-api-key": os.environ["IMPRIME_API_KEY"]}, json={ "client": "ACME Corp", "discount": True, "lines": [{"label": "A5 flyers", "price": "$85"}], "total": "$205.00", }, timeout=60,)res.raise_for_status()pdf = res.content$ch = curl_init("https://app.imprime.io/api/export/{$templateId}/pdf");curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'x-api-key: ' . getenv('IMPRIME_API_KEY'), 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => json_encode([ 'client' => 'ACME Corp', 'total' => '$205.00', ]),]);$pdf = curl_exec($ch);if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) throw new RuntimeException($pdf);file_put_contents('quote.pdf', $pdf);Errors
Section titled “Errors”| Status | Example body | Cause |
|---|---|---|
400 |
{ "error": "Required variable \"total\" is missing" } |
A required variable has no value |
400 |
{ "code": "VARIABLE_TOO_LONG", "error": "Variable \"client\" is longer than its max length of 28 characters" } |
A value exceeds maxLength |
401 |
{ "code": "UNAUTHENTICATED", "error": "Authentication required" } |
Missing, invalid or revoked API key |
404 |
{ "code": "TEMPLATE_NOT_FOUND", "error": "Template not found" } |
Wrong ID, or not your template |
408 |
{ "error": "PDF generation timed out after 30s" } |
Rendering exceeded 30 seconds |