Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tutosrive/factus_challenge/llms.txt

Use this file to discover all available pages before exploring further.

This endpoint retrieves the PDF version of an electronic invoice encoded as a base64 string. The backend proxies the request to GET /v1/bills/download-pdf/{number} on the Factus API and returns the result wrapped in the standard response envelope. The base64 string can be decoded client-side to render the PDF inline in a browser, trigger a file download, or store the PDF in a file system.

Endpoint

GET /factura-download/:number

Path Parameter

number
string
required
The full invoice number (e.g., SETP990009126). This is the same number value returned in the list endpoint’s data[].number field and in data.bill.number from the get/create endpoints.

Request

No request body or query parameters are required. The backend internally calls GET /v1/bills/download-pdf/{number} on the Factus API with the server-stored Bearer token.

Response

200 — Success

status
number
Always 200 on success.
message
string
Always "OK" on success.
data
object
The response data object returned directly from the Factus API’s download-pdf endpoint (GET /v1/bills/download-pdf/{number}). It contains the PDF content encoded as a base64 string. The key name within data is defined by the upstream Factus API response shape for that endpoint.
{
  "status": 200,
  "message": "OK",
  "data": { ... }
}

409 — Conflict

Returned when the Factus API responds but with an unexpected status value.
{
  "status": 409,
  "message": "CONFLICT",
  "data": {}
}

500 — Internal Server Error

Two distinct shapes are possible depending on where the error originates: Shape A — upstream call failure (from request_fact internal catch):
{
  "status": 500,
  "error": "ERROR INTERNO",
  "data": {}
}
Optional extra fields may also appear: message (Axios error message), code (Axios error code), error_name (error class name). Shape B — controller-level exception:
{
  "status": 500,
  "messaje": "Hubo un error al intentar realizar la solicitud",
  "error": {}
}
The messaje key (with a j) in Shape B is a known typo in the backend source. Shape A uses error as a plain string ("ERROR INTERNO"), not an object.

Using the Base64 PDF in a Browser

Once you have the base64 string from data, you can decode it and open the PDF in a new browser tab without any server-side file storage:
/**
 * Opens a base64-encoded PDF in a new browser tab.
 * @param {string} base64String - The raw base64 string (without data URI prefix).
 */
function openPdfFromBase64(base64String) {
  // Convert the base64 string to a binary byte array
  const byteCharacters = atob(base64String);
  const byteNumbers = new Uint8Array(byteCharacters.length);
  for (let i = 0; i < byteCharacters.length; i++) {
    byteNumbers[i] = byteCharacters.charCodeAt(i);
  }

  // Wrap it in a Blob with the PDF MIME type
  const blob = new Blob([byteNumbers], { type: "application/pdf" });

  // Create a temporary object URL and open it
  const url = URL.createObjectURL(blob);
  window.open(url, "_blank");

  // Optional: revoke the URL after a short delay to free memory
  setTimeout(() => URL.revokeObjectURL(url), 10000);
}

Code Examples

curl -X GET http://localhost:3000/factura-download/SETP990009126 \
  -H "Accept: application/json"
PDF generation on the Factus sandbox may only be available for invoices that have been successfully validated (status === 1). Attempting to download a PDF for an unvalidated invoice may result in a 409 response.

Build docs developers (and LLMs) love