Install the client

Install the npm client and render PDFs with an API key.

1. Install the package

npm install tuix-pdf-service-client

2. Configure the client

Configure the client with the base URL and your API key. The API key goes into the headers option, as the x-api-key header.

import { ClientApi, Configuration } from 'tuix-pdf-service-client'
 
export const pdfClient = new ClientApi(
    new Configuration({
        basePath: process.env.API_BASE_URL,
        headers: {
            'x-api-key': process.env.TUIX_PDF_API_KEY,
        },
    }),
)

An API key grants full access to the API and belongs on the server only. To render from a frontend app, proxy the call through your own backend, see Call it from another service.

3. Render a PDF

import { randomUUID } from 'node:crypto'
 
const response = await pdfClient.aPICreatePdfByTemplate({
    applicationId: 'YOUR_APPLICATION_ID',
    createPdfRequestDTO: {
        payloads: [
            {
                id: randomUUID(),
                templateId: 'YOUR_TEMPLATE_ID',
                data: { customerName: 'Jane Doe', total: '249.00' },
            },
        ],
    },
})
 
console.log(response.generatedDocuments)
// [{ id: '…', fileId: 'f2c1…', templateId: '…', url: 'https://…/api/applications/…/pdf-files/f2c1…' }]

id is your own identifier for the document. The service does not interpret it, it echoes it back in the response so you can match results to requests. Use a UUID, e.g. your order or invoice ID.

fileId is the id the service gave the rendered file, and the last segment of url. Store it if you would rather keep your own reference and build the download request from applicationId and fileId.

url is the endpoint the PDF is served from. It is not a public link: fetching it needs the same API key, see Download a PDF.

data is a plain object; its keys are the template variables. See Template syntax and Request reference.

4. Render several documents at once

payloads is an array, so one call can render a batch. Documents may come from different templates of the same application:

const { generatedDocuments } = await pdfClient.aPICreatePdfByTemplate({
    applicationId: 'YOUR_APPLICATION_ID',
    createPdfRequestDTO: {
        payloads: orders.map((order) => ({
            id: order.id,
            templateId: 'YOUR_TEMPLATE_ID',
            data: { customerName: order.customer, total: order.total },
        })),
    },
})

The response arrives once every document in the batch is rendered, and a single failing document fails the whole request. Keep batches small enough to stay inside your own request timeout.

On this page