Smart Report PDF を生成する
既存の SmartReport に対して "puppeteer" または "pdfkit" を使用して PDF をレンダリングし、任意で verificationScore を算出して、downloadUrl と htmlUrl とともに base64 エンコードされた PDF バッファを受け取ります。
成功すると、このエンドポイントはレポートを 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
このエンドポイントは(カスタム printHtml ドキュメントに対応するため)最大 64 MB の JSON ペイロードを受け付けます。お客様自身のクライアント別 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 始まりの行インデックス。デフォルトは行 0 です。 |
printHtml | string | いいえ | <html を含むテーマなしテンプレートで使用する完全な HTML 文字列(最大 64000000 文字)。 |
score | boolean | いいえ | verificationScore を計算し、レポートに verificationScoreSummary を保存するかどうか。 |
scoreProfile | string | いいえ | score が有効な場合に使用するスコアリングプロファイル識別子。最大 64 文字。 |
レンダリングとスコアリングの動作
- デフォルトの行選択:
rowIndexを省略すると、生成は行0がデフォルトになります。範囲外の行をリクエストすると409 Conflict(row_not_found)が返ります。 - カスタム HTML(
printHtml): 完全な<htmlマークアップを提供するテーマなしテンプレートを扱う場合は、printHtml(最大64000000文字)を渡します。 - 検証スコアリング:
score: true(および任意でscoreProfile)を設定すると、verificationScoreを計算してレスポンスのトップレベルに返し、SmartReportにverificationScoreSummaryを保存します。不明なプロファイルは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 | 1 つ以上のフィールドで Joi 検証に失敗しました。 |
409 | row_not_found | 要求された rowIndex がバッチ内に存在しません。 |
409 | unknown_score_profile | 要求された scoreProfile が認識されません。 |
422 | UnprocessableEntity | Mongoose 検証エラーです。 |
500 | InternalServerError | PDF レンダリングまたは内部処理の失敗(レポートを "failed" にマークし smart_batch_report_generation_failed を発火します)。 |
Webhook と MCP 統合
- Webhook: PDF 作成が成功すると
smart_batch_report_generatedを発火し、レンダリングエラーが発生するとsmart_batch_report_generation_failedを発火します(同時にstatusを"failed"に更新します)。詳細は SmartReports Webhook を参照してください。 - MCP 相当ツール: AI エージェントは
smart_report_generate_pdfMCP ツールを使用してレポート PDF を直接レンダリングできます。詳細は MCP と AI エージェント を参照してください。
注記
pdf.bufferには base64 エンコードされた PDF バイト列が JSON レスポンス内に直接含まれます。バイナリ PDF ストリームをご希望の場合は、Smart Report PDF をダウンロードする を呼び出してください。scoreが有効な場合、レスポンスにverificationScoreが含まれます。