Download a PDF

Fetch a generated PDF from its URL with your API key.

The url of a generated document is an endpoint of the Tuix PDF Service, not a public link. Fetching it needs the same API key you used to render, sent in the same x-api-key header.

Endpoint

GET {API_BASE_URL}/api/applications/{applicationId}/pdf-files/{fileId}

You normally never build this URL yourself: it comes back ready to use in generatedDocuments[].url. Store that value and request it as it is.

Headers

HeaderRequiredValue
x-api-keyYesThe same API key you render with. See API Keys.
AcceptYesapplication/pdf. Any other value returns the file base64 encoded.

Accept is not optional. A request without it is rejected with 400, and a request with a different value still answers 200, but with a base64 string instead of the PDF bytes.

Example

const downloadPdf = async (url: string) => {
    const response = await fetch(url, {
        headers: {
            'x-api-key': process.env.TUIX_PDF_API_KEY!,
            Accept: 'application/pdf',
        },
    })
 
    if (!response.ok) {
        throw new Error(`PDF download failed: ${response.status}`)
    }
 
    return Buffer.from(await response.arrayBuffer())
}

Response

200 OK with the bytes of the PDF and Content-Type: application/pdf. The body is the file itself, there is no JSON envelope around it.

Status codes

StatusMeaning
200The file is returned.
400Malformed applicationId or fileId, or no Accept header.
401No API key sent.
403Unknown or deleted API key.
404No document with that fileId in that application.
500The file could not be read.

Serving the file to a browser?

The URL is not shareable: a browser opening it sends neither the API key nor the Accept header, so it gets an error rather than the file. And an API key must never reach a browser, it grants full access to the API.

Download the file in your backend and serve it from there:

browser ──▶ your endpoint ──x-api-key──▶ Tuix PDF Service
        ◀── PDF bytes ─────

Your endpoint decides what happens next: stream the bytes back, store the file, attach it to an email, or hand out a link of your own with your own access rules.

On this page