メインコンテンツまでスキップ

複数PDF同期生成(ZIP)

POST /file/sync/multiple エンドポイントは、指定されたデザインと複数のパラメータから複数のPDFファイルを同期的に生成し、ZIPファイルで返します。

エンドポイント情報

  • URL: https://api.re-port-flow.com/v1/file/sync/multiple
  • メソッド: POST
  • 認証: appkey ヘッダーが必要
  • タイムアウト: 120秒
  • リクエストサイズ上限: 50MB(Base64エンコード後、実質約37MB相当)

使用例

cURL

curl -X POST https://api.re-port-flow.com/v1/file/sync/multiple \
-H "appkey: your-application-key" \
-H "Content-Type: application/json" \
-d '{
"designId": "550e8400-e29b-41d4-a716-446655440000",
"version": 1,
"contents": [
{
"fileName": "invoice_001.pdf",
"shareType": "workspace",
"passcodeEnabled": false,
"params": { "customerName": "山田太郎", "invoiceNumber": "INV-001" }
},
{
"fileName": "invoice_002.pdf",
"shareType": "workspace",
"passcodeEnabled": false,
"params": { "customerName": "佐藤花子", "invoiceNumber": "INV-002" }
}
]
}' \
--output invoices.zip

JavaScript

import axios from 'axios';
import fs from 'fs';

async function generateMultiplePDFs(designId, contents) {
const response = await axios.post(
'https://api.re-port-flow.com/v1/file/sync/multiple',
{ designId, version: 1, contents },
{
headers: { 'appkey': process.env.APP_KEY },
responseType: 'arraybuffer'
}
);

const requestId = response.headers['request-id'];
const fileUrl = response.headers['file-url'];
const fileMapping = JSON.parse(response.headers['x-file-mapping']);

console.log('生成されたファイル:', fileMapping.map(f => ({ fileId: f.fileId, fileName: f.fileName, share: f.share })));

return { data: response.data, requestId, fileUrl, fileMapping };
}

// 使用例
const contents = [
{ fileName: 'invoice_001.pdf', shareType: 'workspace', passcodeEnabled: false, params: { customerName: '山田太郎', invoiceNumber: 'INV-001' } },
{ fileName: 'invoice_002.pdf', shareType: 'workspace', passcodeEnabled: false, params: { customerName: '佐藤花子', invoiceNumber: 'INV-002' } }
];

const result = await generateMultiplePDFs('550e8400-...', contents);
fs.writeFileSync('invoices.zip', result.data);

リクエストパラメータ

フィールド必須説明
designIdstring (UUID)デザインID
versionintegerバージョン番号
contentsarrayContentDtoの配列(最小1件)
contents[].fileNamestringファイル名(/ \\ : * ? " < > | および制御文字以外は使用可能。配列内で一意であること(大文字・小文字は区別しない))
contents[].shareTypestring-共有タイプ(workspace / invited / public、デフォルト: workspace
contents[].passcodeEnabledboolean-パスコード保護(デフォルト: false
contents[].passthroughobject-レスポンスの X-File-Mapping に透過する任意のメタデータ(例: { "pageId": "abc123" }
contents[].paramsobjectパラメータ(デザインパラメータ取得APIで構造を確認可能)

レスポンス

成功時 (200 OK)

レスポンスボディ: ZIPファイル(バイナリ)

レスポンスヘッダー:

ヘッダー説明
Content-Typeコンテンツタイプapplication/zip
Content-Lengthファイルサイズ(バイト)307200
Content-Dispositionファイル名attachment; filename="files.zip"
File-URLZIPダウンロードURLhttps://api.re-port-flow.com/v1/file/download/{requestId}
Request-IdリクエストID550e8400-e29b-41d4-a716-446655440000
X-File-Mappingファイル情報と共有設定(JSON配列)下記参照

X-File-Mapping の構造:

[
{
"fileId": "aaa111",
"fileName": "invoice_001.pdf",
"passthrough": { "pageId": "abc123" },
"share": {
"shareType": "workspace",
"url": "https://app.re-port-flow.com/file/{requestId}/aaa111",
"passcodeEnabled": false
}
},
{
"fileId": "bbb222",
"fileName": "invoice_002.pdf",
"share": {
"shareType": "workspace",
"url": "https://app.re-port-flow.com/file/{requestId}/bbb222",
"passcodeEnabled": false
}
}
]

passthrough フィールドは contents[].passthrough を指定したエントリのみに含まれます。

エラー時

単一PDF同期生成と同様のエラーレスポンスに加え、以下のエラーが返される場合があります。

400 Bad Request(fileName 重複)

{
"statusCode": 400,
"message": [
"contents 内の fileName が重複しています(大文字・小文字は区別されません)。各ファイルには一意の名前を指定してください。"
],
"error": "Bad Request"
}

原因: contents 配列内に同じ fileName(大文字・小文字の違いのみを含む)が複数存在する

ユースケース

月次請求書の一括生成

async function generateMonthlyInvoices(month) {
const invoices = await getInvoicesByMonth(month);

const contents = invoices.map(invoice => ({
fileName: `invoice_${invoice.number}.pdf`,
shareType: 'workspace',
passcodeEnabled: false,
params: invoice
}));

const result = await generateMultiplePDFs('invoice-template-id', contents);
fs.writeFileSync(`invoices_${month}.zip`, result.data);
}

次のステップ