Quickstart
Make your first call to docsgen, receive the PDF on your server and pass it on to your user, in four steps.
The call
A POST with the key in the header and the body in JSON. The response is the raw PDF, with content-type: application/pdf.
curl -X POST "https://docsgen.piensait.com/api/documents" \
-H "authorization: Bearer $DOCGEN_API_KEY" \
-H "content-type: application/json" \
-d @cuenta-de-cobro.json \
-o cuenta.pdfconst response = await fetch(process.env.DOCGEN_URL, {
method: 'POST',
headers: {
authorization: `Bearer ${process.env.DOCGEN_API_KEY}`,
'content-type': 'application/json',
},
body: JSON.stringify({ type: 'cuenta-de-cobro', data }),
});
if (!response.ok) {
// The error comes back as JSON and says what is missing, with the field. It is not a generic 500.
throw new Error((await response.json()).error);
}
const pdf = Buffer.from(await response.arrayBuffer());Passing the PDF on to your user
The usual next step is to re-send it to the user with whatever file name suits you:
return new Response(pdf, {
headers: {
'content-type': 'application/pdf',
'content-disposition': `attachment; filename="CuentaCobro-${numero}.pdf"`,
},
});
The call is always made from your server, never from the browser. See Authentication.
Example bodies
There is a complete example body for each type, and they are not merely illustrative: they are part of our automated tests. Every time we touch the engine they are generated again, so if one ever stopped working, we would find out before you do.
| Type | Example |
|---|---|
factura |
factura.json |
cuenta-de-cobro |
cuenta-de-cobro.json |
recibo-de-caja |
recibo-de-caja.json |
contrato |
contrato.json |
factura with a design |
factura-premium.json |
factura as a POS receipt |
factura-tirilla.json |
nota-credito |
nota-credito.json |
nota-debito |
nota-debito.json |
recibo-de-caja with a design |
recibo-de-caja-premium.json |
estado-de-cuenta |
estado-de-cuenta.json |
colilla-de-nomina |
colilla-de-nomina.json |
colilla-de-nomina with integral salary |
colilla-de-nomina-integral.json |
informe, portrait |
informe.json |
informe, landscape |
informe-horizontal.json |
entrada-de-inventario |
entrada-de-inventario.json |
salida-de-inventario |
salida-de-inventario.json |
traslado-de-inventario |
traslado-de-inventario.json |
The fastest way to start is to take the example for your type, replace its data with yours and send it. Then trim whatever doesn’t apply.
Getting started
- Write to us and we will hand over your key. It is shown only once, when it is handed over: we don’t store it anywhere, so if it gets lost we issue another one.
- Take the example for your document type and send it as is, without changing anything: you should get a PDF back. This step separates a connection problem from a data problem.
- Replace it with your real data, field by field.
- Call from your server, never from the browser.
