Reports
Enqueue report generation after a scan finishes and download the latest ready PDF or a named file.
Report generation and download are separate operations. Reports require an eligible organization tier: Pro, Auditor, Enterprise, or Early. A report permission/tier failure remains a 403 even when scan reads work.
Enqueue generation after scan completion
const scan = await client.scans.get(scanRef);
if (scan.status !== "completed") {
throw new Error("The intended scan has not completed successfully");
}
// Persist a generation intent before this call, and enqueue once for that intent.
const queued = await client.reports.generate(projectRef);
// Persist queued.job_id and mark this intent as acknowledged.The result is:
type ReportGeneration = {
project_id: string;
job_id: string;
status: "queued";
};HTTP 202 means queued, not ready. generate sends one bodyless POST; it does not start a scan, wait for the report, or automatically retry on failure. A later cron invocation or refresh can try downloading the report. Keep generation separate from repeated download/refresh calls so you do not enqueue duplicate jobs.
The generation request accepts no scan ID. At execution time the worker selects its latest eligible completed or failed scan. For a successful-assessment workflow, enqueue after the intended scan completes and serialize later scans/report work. There is no public report-job status endpoint.
Download the latest available PDF
const report = await client.reports.download(projectRef, {
timeoutMs: 120_000,
});
if (report === null) {
console.log("No PDF report is currently available");
} else {
console.log(report.filename, report.contentType, report.bytes.byteLength);
}The call lists reports and downloads the newest available PDF. It returns null when the inventory is empty, no PDF is ready, or the selected file disappears before retrieval. Markdown-only entries are skipped. Download does not enqueue generation or wait for readiness.
Available PDFs are ordered by parsed created_at, then numeric filename order for equal timestamps, and lexical order for a remaining tie. This handles names such as _9 and _10 without relying on the server's reverse filename ordering. Both requests share one deadline and cancellation budget.
A newer pending job does not hide an older available PDF. The latest download is project-scoped: it does not prove that a file belongs to your latest scan or last queued job.
Only absence of a ready PDF, or a 404 retrieving the selected file, becomes null. A missing project/list endpoint, 401/403, provider failures, malformed metadata, incompatible content type, network failures, timeout, and cancellation remain typed errors. See error handling.
List files and download a specific file
const inventory = await client.reports.list(projectRef);
const files = inventory.reports;type ReportFile = {
stem: string;
markdown_filename: string;
pdf_filename: string | null;
created_at: string;
};The list retains provider order. created_at is the Markdown file's modification timestamp, not the scan end time. A null pdf_filename can mean rendering is pending or failed.
const report = await client.reports.download(projectRef, selectedFilename, {
timeoutMs: 120_000,
});selectedFilename must come from the file listing. The explicit overload returns PDF or Markdown bytes and keeps an explicitly requested missing file as an HTTP 404 error. Filenames must be single segments; separators, traversal, control characters and invalid Unicode are rejected. Attachment filename metadata is used only after sanitization.
type ReportDownload = {
filename: string;
contentType: string;
bytes: Uint8Array;
};The SDK reads exact bytes and does not write to disk. In a Node.js application, choose your own destination and hash the downloaded bytes:
import { createHash } from "node:crypto";
import { writeFile } from "node:fs/promises";
const report = await client.reports.download(projectRef);
if (report !== null) {
const sha256 = createHash("sha256").update(report.bytes).digest("hex");
await writeFile("./assessment-report.pdf", report.bytes);
// Persist sha256 with the request, project, scan, and original listing filename.
}For compliance evidence, establish attribution before attaching a file to a specific scan. Save the pre-generation inventory, serialize project use, and identify a unique new candidate. Download that filename explicitly after your application confirms attribution. Multiple candidates or external project activity can require reconciliation. Reuse evidence for the same original filename/hash; changed bytes represent a new version.
Last updated