Skip to main content

从文件创建 Smart Batch

将 CSV、XLSX 或 JSONL 载荷导入为一个新的 SmartBatch。服务器会解码原始文本或 base64 数据 URL,强制执行 MAX_ROWS(默认为 20000)限制,将列标题和驼峰命名(camelCase)别名解析匹配到你的 BatchConfiguration 步骤依赖项,并计算积分费用估算。

通过校验的行会以 pending 状态保存在批次上,而格式错误的行会在 rejectedRows 中返回。传入 autoStart: true 可验证账户的端点权限并立即开始处理;否则不会执行任何核验,也不会消耗积分。

接口​

POST https://api.verifik.co/v2/smart-batches/from-file

此接口也可通过 Smart-Agent 代理 https://ai.verifik.co/v2/smart-batches/from-file 访问,需使用你自己的客户专属 Authorization: Bearer <VERIFIK_JWT>。共享 x402 执行会被拒绝并返回 403 Forbidden。

请求头​

名称值描述
Content-Typeapplication/json请求载荷格式。
AuthorizationBearer <VERIFIK_JWT>客户作用域的 JWT(authUser.clientId)。

请求体​

名称类型必填描述
batchConfigurationstring是已认证客户拥有的 BatchConfiguration ObjectId。
namestring是批次显示名称。最多 150 个字符。
contentstring是原始 CSV/JSONL 文本或 base64 数据 URL(data:<mime>;base64,<payload>)。
formatstring否输入格式:"csv"、"xlsx" 或 "jsonl"。默认为 batchConfiguration.inputFormat 或 "csv"。
autoStartboolean否设为 true 时,在导入后立即启动创建的批次。

未知请求体键将被 Joi 校验拒绝,并返回 409 MissingParameter。

请求示例​

import axios from "axios";

const run = async () => {
const { data } = await axios.post(
"https://api.verifik.co/v2/smart-batches/from-file",
{
batchConfiguration: "6801a2b3c4d5e6f7a8b9c0d4",
name: "November CSV Import",
format: "csv",
content: "Document Type,Document Number\nCC,1032386359\nCC,1007463534\n",
autoStart: false,
},
{
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.VERIFIK_JWT}`,
},
}
);

console.log(data);
};

run();

响应示例​

{
"data": {
"batch": {
"_id": "6801a2b3c4d5e6f7a8b9c0d3",
"batchConfiguration": "6801a2b3c4d5e6f7a8b9c0d4",
"client": "507f1f77bcf86cd799439013",
"name": "November CSV Import",
"status": "pending",
"executor": "browser",
"source": "smart_batch",
"headlessRun": false,
"creditsSpent": 0,
"rows": [
{
"rowIndex": 0,
"inputData": {
"Document Type": "CC",
"documentType": "CC",
"Document Number": "1032386359",
"documentNumber": "1032386359"
},
"status": "pending",
"results": {},
"errors": []
},
{
"rowIndex": 1,
"inputData": {
"Document Type": "CC",
"documentType": "CC",
"Document Number": "1007463534",
"documentNumber": "1007463534"
},
"status": "pending",
"results": {},
"errors": []
}
],
"totalRows": 2,
"completedRows": 0,
"failedRows": 0,
"partialRows": 0,
"createdAt": "2026-11-24T20:05:00.000Z",
"updatedAt": "2026-11-24T20:05:00.000Z"
},
"columns": [
"Document Type",
"documentType",
"Document Number",
"documentNumber"
],
"accepted": 2,
"rejected": 0,
"rejectedRows": [],
"estimate": {
"itemCount": 2,
"creditsPerItem": 0.04,
"totalCredits": 0.08,
"breakdown": [
{
"sequence": 1,
"featureCode": "co-cedula",
"price": 0.04,
"total": 0.08
}
]
}
}
}

注意事项​

  • 文件解析强制执行 MAX_ROWS(默认 20000),并自动生成驼峰命名(camelCase)表头别名,从而使 Document Number 这类列名可以解析为 documentNumber。
  • 对于 .xlsx 工作簿,请搭配 format: "xlsx" 传入 base64 数据 URL(data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,<payload>)。
  • 409 Conflict 错误包括 batch_file_has_no_sheets、batch_file_is_empty、batch_file_has_no_rows、batch_file_has_no_usable_rows、batch_jsonl_parse_failed_on_line_<N>、batch_configuration_has_no_steps 和 endpoints_not_in_account。
  • 无效行校验(0 个有效行)、不支持的格式错误以及 MAX_ROWS 阈值错误均返回 HTTP 500。

相关文档​