Skip to main content

生成 Smart Report PDF

使用 "puppeteer" 或 "pdfkit" 为现有 SmartReport 渲染 PDF,按需计算 verificationScore,并在响应中返回 base64 编码的 PDF 缓冲区以及 downloadUrl 和 htmlUrl。

成功后,此端点会将报告状态标记为 status: "generated",并在启用评分时持久化 verificationScoreSummary,同时触发 smart_batch_report_generated Webhook。如果 PDF 生成失败,报告会被标记为 status: "failed" 并触发 smart_batch_report_generation_failed Webhook。

端点​

POST https://api.verifik.co/v2/smart-reports/{id}/generate

此端点最高接受 64 MB 的 JSON 负载(以容纳自定义 printHtml 文档)。使用你自己的每客户 Authorization: Bearer <VERIFIK_JWT>,也可通过 Smart-Agent 代理地址 https://ai.verifik.co/v2/smart-reports/{id}/generate 访问。共享 x402 执行会被拦截并返回 403 Forbidden。

请求头​

名称值说明
Content-Typeapplication/json请求体负载格式(上限 64 MB)。
AuthorizationBearer <VERIFIK_JWT>客户作用域 JWT(authUser.clientId)。

参数​

名称类型必填说明
idstring是SmartReport ObjectId。

请求体参数​

名称类型必填说明
enginestring否PDF 渲染引擎:"pdfkit" 或 "puppeteer"。
rowIndexnumber否关联 SmartBatch 中从零开始的行索引。默认使用第 0 行。
printHtmlstring否完整 HTML 字符串(最长 64000000 个字符),用于包含 <html 的非主题模板。
scoreboolean否是否计算 verificationScore 并将 verificationScoreSummary 保存到报告上。
scoreProfilestring否启用 score 时使用的评分配置标识符。最长 64 个字符。

渲染与评分行为​

  • 默认行选择:省略 rowIndex 时默认生成第 0 行。请求超出范围的行号会返回 409 Conflict(row_not_found)。
  • 自定义 HTML(printHtml):使用提供完整 <html 标记的非主题模板时,可传入 printHtml(最多 64000000 个字符)。
  • 核验评分:设置 score: true(以及可选的 scoreProfile)即可计算 verificationScore,在响应顶层返回该字段,并将 verificationScoreSummary 保存在 SmartReport 上。传入未知的评分配置会返回 409 Conflict(unknown_score_profile)并失败。

请求示例​

import axios from "axios";

const run = async () => {
const id = "6801a2b3c4d5e6f7a8b9c0d1";
const { data } = await axios.post(
`https://api.verifik.co/v2/smart-reports/${id}/generate`,
{
engine: "puppeteer",
rowIndex: 0,
score: true,
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.VERIFIK_JWT}`,
},
}
);

console.log({
status: data.data.status,
pdfSize: data.pdf.size,
downloadUrl: data.pdf.downloadUrl,
});
};

run();

响应示例​

{
"data": {
"_id": "6801a2b3c4d5e6f7a8b9c0d1",
"template": "6801a2b3c4d5e6f7a8b9c0d2",
"smartBatch": "6801a2b3c4d5e6f7a8b9c0d3",
"name": "Background Check - Applicant 42",
"status": "generated",
"pdfEngine": "puppeteer",
"pdfSize": 148320,
"generationDurationMs": 1840,
"generatedAt": "2026-11-24T20:00:04.000Z",
"verificationScoreSummary": {},
"rowIndex": 0,
"externalRefId": "applicant-42"
},
"pdf": {
"buffer": "JVBERi0xLjQK...",
"size": 148320,
"engine": "puppeteer",
"generationDurationMs": 1840,
"downloadUrl": "/v2/smart-reports/6801a2b3c4d5e6f7a8b9c0d1/download",
"htmlUrl": "/v2/smart-reports/6801a2b3c4d5e6f7a8b9c0d1/html"
},
"verificationScore": {}
}

错误码说明​

状态码错误码 / 类型原因
401UnauthorizedJWT 缺失或无效。
403Forbidden尝试使用共享 x402 执行;请改用你自己的每客户 JWT。
404not_found报告 ID 不存在或属于其他客户。
404template_not_found无法找到关联的模板。
404batch_not_found无法找到关联的 SmartBatch。
409MissingParameter一个或多个字段未通过 Joi 校验。
409row_not_found所请求的 rowIndex 在批次中不存在。
409unknown_score_profile所请求的 scoreProfile 未被识别。
422UnprocessableEntityMongoose 校验错误。
500InternalServerErrorPDF 渲染或内部处理失败(会将报告标记为 "failed" 并触发 smart_batch_report_generation_failed)。

Webhooks 与 MCP 集成​

  • Webhooks:PDF 创建成功时触发 smart_batch_report_generated,渲染发生错误时触发 smart_batch_report_generation_failed(并将 status 更新为 "failed")。详见 SmartReports Webhooks。
  • MCP 等效工具:AI 智能体可通过 smart_report_generate_pdf MCP 工具直接渲染报告 PDF。详见 MCP 与 AI 智能体。

注意事项​

  • pdf.buffer 会直接在 JSON 响应中包含 base64 编码的 PDF 字节;如果更倾向获取二进制 PDF 流,请调用 下载 Smart Report PDF。
  • 启用 score 时,响应中会包含 verificationScore。

相关页面​