生成 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-Type | application/json | 请求体负载格式(上限 64 MB)。 |
Authorization | Bearer <VERIFIK_JWT> | 客户作用域 JWT(authUser.clientId)。 |
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 是 | SmartReport ObjectId。 |
请求体参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
engine | string | 否 | PDF 渲染引擎:"pdfkit" 或 "puppeteer"。 |
rowIndex | number | 否 | 关联 SmartBatch 中从零开始的行索引。默认使用第 0 行。 |
printHtml | string | 否 | 完整 HTML 字符串(最长 64000000 个字符),用于包含 <html 的非主题模板。 |
score | boolean | 否 | 是否计算 verificationScore 并将 verificationScoreSummary 保存到报告上。 |
scoreProfile | string | 否 | 启用 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)并失败。
请求示例
- Node.js
- PHP
- Python
- Go
- cURL
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();
<?php
$id = "6801a2b3c4d5e6f7a8b9c0d1";
$ch = curl_init("https://api.verifik.co/v2/smart-reports/" . $id . "/generate");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Authorization: Bearer " . getenv("VERIFIK_JWT"),
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
"engine" => "puppeteer",
"rowIndex" => 0,
"score" => true,
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
import os
import requests
report_id = "6801a2b3c4d5e6f7a8b9c0d1"
url = f"https://api.verifik.co/v2/smart-reports/{report_id}/generate"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {os.getenv('VERIFIK_JWT')}",
}
payload = {
"engine": "puppeteer",
"rowIndex": 0,
"score": True,
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
id := "6801a2b3c4d5e6f7a8b9c0d1"
body, _ := json.Marshal(map[string]interface{}{
"engine": "puppeteer",
"rowIndex": 0,
"score": true,
})
req, _ := http.NewRequest("POST", "https://api.verifik.co/v2/smart-reports/"+id+"/generate", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+os.Getenv("VERIFIK_JWT"))
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
var out map[string]interface{}
json.NewDecoder(resp.Body).Decode(&out)
fmt.Println(out)
}
curl -X POST "https://api.verifik.co/v2/smart-reports/6801a2b3c4d5e6f7a8b9c0d1/generate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VERIFIK_JWT" \
-d '{
"engine": "puppeteer",
"rowIndex": 0,
"score": true
}'
响应示例
- 200 OK
- 401
- 403
- 404
- 409
- 422
- 500
{
"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": {}
}
{
"message": "Unauthorized",
"code": "Unauthorized"
}
{
"message": "Shared x402 execution is forbidden on this endpoint",
"code": "Forbidden"
}
{
"message": "template_not_found",
"code": "NotFound"
}
{
"message": "row_not_found",
"code": "row_not_found"
}
{
"message": "UnprocessableEntity",
"code": "UnprocessableEntity"
}
{
"message": "InternalServerError",
"code": "InternalServerError"
}
错误码说明
| 状态码 | 错误码 / 类型 | 原因 |
|---|---|---|
401 | Unauthorized | JWT 缺失或无效。 |
403 | Forbidden | 尝试使用共享 x402 执行;请改用你自己的每客户 JWT。 |
404 | not_found | 报告 ID 不存在或属于其他客户。 |
404 | template_not_found | 无法找到关联的模板。 |
404 | batch_not_found | 无法找到关联的 SmartBatch。 |
409 | MissingParameter | 一个或多个字段未通过 Joi 校验。 |
409 | row_not_found | 所请求的 rowIndex 在批次中不存在。 |
409 | unknown_score_profile | 所请求的 scoreProfile 未被识别。 |
422 | UnprocessableEntity | Mongoose 校验错误。 |
500 | InternalServerError | PDF 渲染或内部处理失败(会将报告标记为 "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_pdfMCP 工具直接渲染报告 PDF。详见 MCP 与 AI 智能体。
注意事项
pdf.buffer会直接在 JSON 响应中包含 base64 编码的 PDF 字节;如果更倾向获取二进制 PDF 流,请调用 下载 Smart Report PDF。- 启用
score时,响应中会包含verificationScore。