Render with fetch

Render PDFs without the npm package, straight against the REST API with an API key.

If the npm package isn't available, render directly against the REST API. The endpoint takes JSON and an API key in the x-api-key header.

Endpoint

POST {API_BASE_URL}/api/applications/{applicationId}/pdf-files

Example

const response = await fetch(
    `${API_BASE_URL}/api/applications/YOUR_APPLICATION_ID/pdf-files`,
    {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'x-api-key': process.env.TUIX_PDF_API_KEY,
        },
        body: JSON.stringify({
            payloads: [
                {
                    id: crypto.randomUUID(),
                    templateId: 'YOUR_TEMPLATE_ID',
                    data: { customerName: 'Jane Doe', total: '249.00' },
                },
            ],
        }),
    },
)
 
if (!response.ok) {
    throw new Error(`PDF render failed: ${response.status}`)
}
 
const { generatedDocuments } = await response.json()

Response

{
    "generatedDocuments": [
        {
            "id": "0f7c2d20-1f6e-4f3f-9c14-8d6d4c5f1a2b",
            "fileId": "f2c1a0d4-7c2e-4e1a-9a9b-3d5f6c7b8a90",
            "templateId": "8b9f0f4a-6f21-4a1e-9d7a-1c2f3e4d5a6b",
            "url": "https://…/api/applications/3b7f1c9e-2d4a-4b8c-9e1f-0a2b3c4d5e6f/pdf-files/f2c1a0d4-7c2e-4e1a-9a9b-3d5f6c7b8a90"
        }
    ]
}

url is the endpoint the PDF is served from, not a public link. Request it with the same x-api-key header you rendered with, plus Accept: application/pdf, see Download a PDF.

An API key grants full access to the API. Do not call this endpoint straight from the browser with your key, proxy it through your own backend, see Call it from another service.

All fields and status codes are listed in the Request reference.

On this page