INTEGRACIÓN / V1

Tu primera petición PDF.

Un template, una API key y JSON. Esta guía usa los mismos datos ficticios que la vista previa de la página principal.

01 / Crea tu template

Abre la Console, guarda el HTML de ejemplo como template y copia su template_id. Crea una API key para la misma cuenta. Guárdala en tu servidor en SYSINVOICE_API_KEY; nunca en el código del navegador.

Console

El template de ejemplo

Este ejemplo A4 mínimo admite una línea con cantidad 1. Calcula los totales en tu aplicación para facturas más complejas. El CSS está incorporado; no necesita recursos remotos ni scripts.

Descargar template HTML
El template de ejemplo
<!doctype html>
<html lang="en"><head><meta charset="utf-8">
<style>
@page { size: A4; margin: 0; }
* { box-sizing: border-box; }
body { margin: 0; padding: 64px; color: #15223b; font: 15px Arial, sans-serif; }
header { display: flex; justify-content: space-between; border-bottom: 3px solid #0891b2; padding-bottom: 32px; }
h1 { font-size: 38px; margin: 0 0 10px; letter-spacing: -1px; }
h2 { font-size: 16px; margin: 0 0 8px; }
p { line-height: 1.7; }
.muted { color: #526078; font-size: 12px; }
.meta { margin: 38px 0; display: flex; justify-content: space-between; }
table { width: 100%; border-collapse: collapse; margin-top: 42px; }
th { padding: 14px 8px; text-align: left; background: #f1f5f9; color: #526078; font-size: 11px; }
td { padding: 22px 8px; border-bottom: 1px solid #dbe2eb; }
.right { text-align: right; }
.total { display: flex; justify-content: space-between; margin-top: 30px; padding: 24px 8px; background: #ecfeff; font-weight: bold; font-size: 20px; }
footer { margin-top: 180px; padding-top: 20px; border-top: 1px solid #dbe2eb; }
</style></head><body>
<header><div><h2>NORTHSTAR / STUDIO</h2><span class="muted">Digital products &amp; engineering</span></div><span class="muted">INVOICE</span></header>
<div class="meta"><div><h1>{{ .invoice_number }}</h1><span class="muted">Issued {{ .issued_at }}</span></div><div><span class="muted">BILL TO</span><p>Acme Labs<br>Sample account</p></div></div>
<table><thead><tr><th>DESCRIPTION</th><th class="right">QTY</th><th class="right">AMOUNT</th></tr></thead><tbody>
{{ range .line_items }}<tr><td>{{ .description }}</td><td class="right">{{ .qty }}</td><td class="right">{{ .amount }} {{ $.currency }}</td></tr>{{ end }}
</tbody></table>
<div class="total"><span>Total</span><span>{{ .total }} {{ .currency }}</span></div>
<p class="muted">Thank you for building with us.</p>
<footer class="muted">SysInvoice / Fictional example / One line item, quantity 1 / 01</footer>
</body></html>

02 / Envía la petición

Sustituye tpl_your_invoice_template por el ID de la Console. El cuerpo JSON admite template_id y document_data, con un máximo de 2 MiB. El ejemplo es ilustrativo y no llama a la API desde este sitio.

Petición
curl --fail-with-body --request POST \  https://api.sysinvoice.com/v1/invoices/generate \  --header "Authorization: Bearer $SYSINVOICE_API_KEY" \  --header 'Content-Type: application/json' \  --header 'Accept: application/pdf' \  --data '{  "template_id": "tpl_your_invoice_template",  "document_data": {    "invoice_number": "INV-2026-001",    "issued_at": "2026-11-10",    "currency": "EUR",    "line_items": [      {        "description": "API integration",        "qty": 1,        "price": 240,        "amount": "240.00"      }    ],    "total": "240.00"  }}' \  --output invoice.pdf
Solo ejemplo: configura tu API key y sustituye template_id por el ID de tu template guardado.

03 / Gestiona la respuesta

Una petición correcta devuelve HTTP 200 y bytes application/pdf, con Cache-Control: no-store y X-Request-Id para diagnóstico. Guarda o transmite la respuesta desde tu aplicación.

Abrir el PDF de ejemplo

Gestiona los errores explícitamente

JSON malformado devuelve 400; credenciales inválidas 401; template desconocido 404; datos inválidos 422. Con 429 respeta Retry-After. Con --fail-with-body, cURL termina con error ante errores HTTP: comprueba la respuesta antes de tratar el archivo como PDF.