运行 Smart Report
在单次请求中执行完整的核验与报告生成流水线。POST /v2/smart-reports/run 是 Reports 的核心无头一体化执行端点:它会自动解析预设(systemKey)或现有 BatchConfiguration(batchConfigurationId),根据配置输入 Schema 校验输入参数,检查账户功能授权,在 FeatureRunner 中运行所有核验步骤,创建 SmartBatch(headlessRun: true)与 SmartReport,按需计算 verificationScore,渲染 PDF/HTML 输出,按需发送邮件并分发 Webhook。
对于规模较小的运行(最多 5 行),执行默认采用同步模式(mode: "sync");若在 90 秒同步窗口内完成,将直接返回 200 OK。对于更大规模的批次或超过 90 秒同步截止时间的运行,接口会自动切换为异步执行并返回 202 Accepted,同时附上轮询地址与下载 URL。
端点
POST https://api.verifik.co/v2/smart-reports/run
当携带你自己的每客户 Authorization: Bearer <VERIFIK_JWT> 请求头进行认证时,也可以通过 Smart-Agent 代理地址 https://ai.verifik.co/v2/smart-reports/run 访问此端点。共享 x402 执行会被拦截并返回 403 Forbidden。
请求头
| 名称 | 值 | 说明 |
|---|---|---|
Content-Type | application/json | 请求体负载格式。 |
Authorization | Bearer <VERIFIK_JWT> | 客户作用域 JWT(authUser.clientId)。 |
必须使用包含客户作用域的 JWT(authUser.clientId)。缺少 clientId 的令牌将返回 409 Conflict(client_context_required)。缺失或无效的 JWT 将返回 401 Unauthorized。
请求体参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
systemKey | string | 条件必填 | 预设标识符。会去除首尾空格,最长 120 个字符,匹配模式 /^[a-z0-9][a-z0-9._-]{1,118}$/i。systemKey 与 batchConfigurationId 至少填写一个。 |
batchConfigurationId | string | 条件必填 | 现有 BatchConfiguration 的 ObjectId。systemKey 与 batchConfigurationId 至少填写一个。 |
templateId | string | 否 | 报告模板 ObjectId。用于覆盖配置或预设上的首选模板。 |
name | string | 否 | 生成的报告和批次的自定义显示名称。最长 150 个字符。 |
inputs | object 或 object[] | 条件必填 | 单个输入对象或输入对象数组(最少 1 个,最多 500 个)。inputs 与 rows 至少填写一个;若同时传入,以 inputs 为准。 |
rows | object[] | 条件必填 | 包含 1 到 500 条行记录的数组,格式可为扁平对象({ ... })或结构化行对象({ rowIndex, inputData })。inputs 与 rows 至少填写一个。 |
mode | string | 否 | "sync" 或 "async"。当行数 <= 5 时默认为 "sync",当行数 > 5 时默认为 "async"。传入超过 5 行却指定 mode: "sync" 将返回 409 Conflict(sync_row_limit_exceeded)。 |
generatePdf | boolean | 否 | 是否在本次运行期间渲染 PDF。默认为 true。注意:若提供了 emailTo,即使 generatePdf 设为 false 也会渲染 PDF。 |
includePdfBase64 | boolean | 否 | 是否在 data.pdf.buffer 中返回 base64 编码的 PDF。默认为 false。 |
pdfEngine | string | 否 | PDF 渲染引擎:"puppeteer" 或 "pdfkit"。默认沿用模板设置或 "puppeteer"。 |
score | boolean | 否 | 是否计算并附加 verificationScore。 |
scoreProfile | string | 否 | 启用 score 时使用的评分配置标识符。最长 64 个字符。 |
rowIndex | integer | 否 | 用于 PDF/HTML/评分输出的从零开始的行索引(>= 0)。默认为 0。 |
emailTo | string[] | 否 | 用于接收报告的有效收件人邮箱地址数组(最多 20 个)。 |
emailSubject | string | 否 | 自定义邮件主题行。最长 250 个字符。 |
emailLanguage | string | 否 | 邮件模板语言:"en" 或 "es"。默认为 "es"。 |
webhookUrl | string | 否 | 单份报告级别的 http 或 https Webhook 覆盖地址。最长 2048 个字符。 |
externalRefId | string | 否 | 调用方提供的关联 ID(最长 200 个字符),会在报告文档与 Webhook 负载中原样返回。 |
createdByChannel | string | 否 | 来源渠道:"portal"、"api"、"mcp"、"x402" 或 "webhook"。默认为 "api"。 |
执行行为与参数规则
- 目标解析(
systemKey与batchConfigurationId):提供预设systemKey或现有的batchConfigurationId。未知的 ID 或预设会返回404 Not Found(batch_configuration_not_found、preset_not_found或template_not_found)。未配置任何步骤的配置或预设会返回409 Conflict(preset_has_no_steps或batch_configuration_has_no_steps)。 - 账户功能授权:在执行前会校验已解析预设或批次配置中的每一步是否均在你的客户账户授权范围之内。未获授权的步骤将返回
409 Conflict(endpoints_not_in_account)并失败。 - 同步截止时间与自动回退:同步运行最多等待
90000毫秒(SYNC_DEADLINE_MS = 90s)。如果核验或渲染在 90 秒内未能完成,API 会自动返回202 Accepted(mode: "async")并附带pollUrl,以便你的集成轮询 获取 Smart Report 或等待 Webhook。 - 邮件触发 PDF 生成:只要设置了
emailTo,即使显式设置generatePdf: false,系统也一定会生成 PDF 用于邮件投递。
请求示例
- Node.js
- PHP
- Python
- Go
- cURL
import axios from "axios";
const run = async () => {
const { data } = await axios.post(
"https://api.verifik.co/v2/smart-reports/run",
{
systemKey: "example-preset",
name: "Background Check - Applicant 42",
inputs: {
documentType: "CC",
documentNumber: "1032386359",
},
mode: "sync",
generatePdf: true,
includePdfBase64: false,
pdfEngine: "puppeteer",
score: true,
emailTo: ["compliance@example.com"],
emailLanguage: "en",
webhookUrl: "https://webhooks.example.com/verifik",
externalRefId: "applicant-42",
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.VERIFIK_JWT}`,
},
}
);
console.log(data);
};
run();
<?php
$ch = curl_init("https://api.verifik.co/v2/smart-reports/run");
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([
"systemKey" => "example-preset",
"name" => "Background Check - Applicant 42",
"inputs" => [
"documentType" => "CC",
"documentNumber" => "1032386359",
],
"mode" => "sync",
"generatePdf" => true,
"includePdfBase64" => false,
"pdfEngine" => "puppeteer",
"score" => true,
"emailTo" => ["compliance@example.com"],
"emailLanguage" => "en",
"webhookUrl" => "https://webhooks.example.com/verifik",
"externalRefId" => "applicant-42",
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
import os
import requests
url = "https://api.verifik.co/v2/smart-reports/run"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {os.getenv('VERIFIK_JWT')}",
}
payload = {
"systemKey": "example-preset",
"name": "Background Check - Applicant 42",
"inputs": {
"documentType": "CC",
"documentNumber": "1032386359",
},
"mode": "sync",
"generatePdf": True,
"includePdfBase64": False,
"pdfEngine": "puppeteer",
"score": True,
"emailTo": ["compliance@example.com"],
"emailLanguage": "en",
"webhookUrl": "https://webhooks.example.com/verifik",
"externalRefId": "applicant-42",
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
body, _ := json.Marshal(map[string]interface{}{
"systemKey": "example-preset",
"name": "Background Check - Applicant 42",
"inputs": map[string]interface{}{
"documentType": "CC",
"documentNumber": "1032386359",
},
"mode": "sync",
"generatePdf": true,
"includePdfBase64": false,
"pdfEngine": "puppeteer",
"score": true,
"emailTo": []string{"compliance@example.com"},
"emailLanguage": "en",
"webhookUrl": "https://webhooks.example.com/verifik",
"externalRefId": "applicant-42",
})
req, _ := http.NewRequest("POST", "https://api.verifik.co/v2/smart-reports/run", 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/run" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $VERIFIK_JWT" \
-d '{
"systemKey": "example-preset",
"name": "Background Check - Applicant 42",
"inputs": {
"documentType": "CC",
"documentNumber": "1032386359"
},
"mode": "sync",
"generatePdf": true,
"includePdfBase64": false,
"pdfEngine": "puppeteer",
"score": true,
"emailTo": ["compliance@example.com"],
"emailLanguage": "en",
"webhookUrl": "https://webhooks.example.com/verifik",
"externalRefId": "applicant-42"
}'
响应示例
- 200 OK(同步)
- 202 Accepted(异步)
- 401
- 403
- 404
- 409
- 422
- 500
{
"data": {
"mode": "sync",
"report": {
"_id": "6801a2b3c4d5e6f7a8b9c0d1",
"name": "Background Check - Applicant 42",
"status": "sent",
"template": "6801a2b3c4d5e6f7a8b9c0d2",
"smartBatch": "6801a2b3c4d5e6f7a8b9c0d3",
"rowIndex": 0,
"externalRefId": "applicant-42",
"createdByChannel": "api",
"createdAt": "2026-11-24T20:00:00.000Z",
"updatedAt": "2026-11-24T20:00:04.000Z"
},
"batch": {
"_id": "6801a2b3c4d5e6f7a8b9c0d3",
"name": "Background Check - Applicant 42",
"status": "completed",
"batchConfiguration": "6801a2b3c4d5e6f7a8b9c0d4",
"totalRows": 1,
"completedRows": 1,
"failedRows": 0,
"partialRows": 0,
"creditsSpent": 2,
"rows": [
{
"rowIndex": 0,
"status": "completed",
"inputData": {
"documentType": "CC",
"documentNumber": "1032386359"
},
"results": {},
"errors": []
}
]
},
"verificationScore": {},
"pdf": {
"size": 148320,
"engine": "puppeteer",
"generationDurationMs": 1840,
"downloadUrl": "/v2/smart-reports/6801a2b3c4d5e6f7a8b9c0d1/download",
"htmlUrl": "/v2/smart-reports/6801a2b3c4d5e6f7a8b9c0d1/html"
},
"email": {
"success": true,
"recipients": ["compliance@example.com"],
"subject": "Verification Report",
"messageId": "<message-id@example.com>"
}
}
}
{
"data": {
"mode": "async",
"report": {
"_id": "6801a2b3c4d5e6f7a8b9c0d1",
"name": "Background Check - Applicant 42",
"status": "pending",
"template": "6801a2b3c4d5e6f7a8b9c0d2",
"smartBatch": "6801a2b3c4d5e6f7a8b9c0d3",
"externalRefId": "applicant-42",
"createdByChannel": "api"
},
"batch": {
"_id": "6801a2b3c4d5e6f7a8b9c0d3",
"name": "Background Check - Applicant 42",
"status": "pending",
"batchConfiguration": "6801a2b3c4d5e6f7a8b9c0d4",
"totalRows": 10,
"completedRows": 0,
"failedRows": 0,
"partialRows": 0,
"creditsSpent": 0,
"rows": []
},
"pollUrl": "/v2/smart-reports/6801a2b3c4d5e6f7a8b9c0d1",
"downloadUrl": "/v2/smart-reports/6801a2b3c4d5e6f7a8b9c0d1/download",
"htmlUrl": "/v2/smart-reports/6801a2b3c4d5e6f7a8b9c0d1/html"
}
}
{
"message": "Unauthorized",
"code": "Unauthorized"
}
{
"message": "Shared x402 execution is forbidden on this endpoint",
"code": "Forbidden"
}
{
"message": "preset_not_found",
"code": "preset_not_found"
}
{
"message": "sync_row_limit_exceeded",
"code": "sync_row_limit_exceeded"
}
{
"message": "UnprocessableEntity",
"code": "UnprocessableEntity"
}
{
"message": "InternalServerError",
"code": "InternalServerError"
}
错误码说明
| 状态码 | 错误码 / 类型 | 原因 |
|---|---|---|
401 | Unauthorized | Authorization 请求头中的 JWT 缺失或无效。 |
403 | Forbidden | 尝试使用共享 x402 执行;请改用你自己的每客户 JWT。 |
404 | batch_configuration_not_found | 指定的 batchConfigurationId 在你的客户下不存在。 |
404 | preset_not_found | 无法解析指定的 systemKey 预设。 |
404 | template_not_found | 指定的 templateId 或所配置的报告模板不存在。 |
409 | MissingParameter | 一个或多个请求字段未通过 Joi Schema 校验。 |
409 | client_context_required | JWT 未携带有效的 authUser.clientId。 |
409 | missing_inputs | inputs 与 rows 均未提供。 |
409 | max_rows_exceeded | 提供了超过 500 条行记录/输入项。 |
409 | sync_row_limit_exceeded | 超过 5 行却请求了 mode: "sync"。 |
409 | missing_required_inputs | 缺少批次配置 Schema 所要求的必填输入项。 |
409 | preset_has_no_steps | 解析到的预设未配置任何核验步骤。 |
409 | batch_configuration_has_no_steps | 目标 BatchConfiguration 未配置任何核验步骤。 |
409 | endpoints_not_in_account | 你的客户账户未对一个或多个已配置的步骤拥有功能授权。 |
409 | row_not_found | 所请求的 rowIndex 在批次中不存在。 |
409 | unknown_score_profile | 所提供的 scoreProfile 未被识别。 |
422 | UnprocessableEntity | Mongoose 校验失败或唯一键冲突。 |
500 | InternalServerError | 执行或渲染过程中发生未知的服务端错误。 |
Webhooks 与 MCP 集成
- Webhooks:当提供了
webhookUrl(或在预设 /BatchConfiguration上配置)时,Verifik 会在报告生成时发送smart_batch_report_generated或smart_batch_report_generation_failed,并在执行emailTo投递时发送smart_batch_report_sent或smart_batch_report_delivery_failed。你的externalRefId会在报告文档与 Webhook 事件中一并返回。详见 SmartReports Webhooks。 - MCP 等效工具:通过 MCP 连接的 AI 智能体可以使用相同的无头参数调用
smart_report_run工具。详见 MCP 与 AI 智能体。
注意事项
- 仅当
generatePdf为true(或emailTo触发了 PDF 渲染)时才会返回data.pdf;仅当includePdfBase64为true时才会返回data.pdf.buffer。 - 仅当传入了
emailTo时才会返回data.email;如果投递失败,data.email.error会包含失败原因。 - 当启用
score时会填充data.verificationScore。