デザインパラメータ取得
GET /file/design/parameter/{designId} エンドポイントは、指定されたデザインIDのパラメータ構造を取得します。PDFやサムネイル生成時に必要なパラメータのスキーマを確認できます。
エンドポイント情報
- URL:
https://api.re-port-flow.com/v1/file/design/parameter/{designId} - メソッド:
GET - 認証:
appkeyヘッダーが必要
使用例
cURL
# 最新バージョンのパラメータを取得
curl -X GET https://api.re-port-flow.com/v1/file/design/parameter/550e8400-e29b-41d4-a716-446655440000 \
-H "appkey: your-application-key"
# 特定バージョンのパラメータを取得
curl -X GET "https://api.re-port-flow.com/v1/file/design/parameter/550e8400-e29b-41d4-a716-446655440000?version=1" \
-H "appkey: your-application-key"
JavaScript
async function getDesignParameters(designId, version = null) {
const baseUrl = 'https://api.re-port-flow.com/v1';
const url = version
? `${baseUrl}/file/design/parameter/${designId}?version=${version}`
: `${baseUrl}/file/design/parameter/${designId}`;
const response = await axios.get(url, {
headers: {
'appkey': process.env.APP_KEY
}
});
return response.data;
}
// 使用例
const schema = await getDesignParameters('550e8400-...');
console.log('パラメータスキーマ:', schema);
Python
def get_design_parameters(design_id, version=None):
base_url = "https://api.re-port-flow.com/v1"
url = f"{base_url}/file/design/parameter/{design_id}"
if version:
url += f"?version={version}"
headers = {
'appkey': os.getenv('APP_KEY')
}
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()
# 使用例
schema = get_design_parameters('550e8400-...')
print('パラメータスキーマ:', schema)
パラメータ
| パラメータ | 型 | 必須 | 説明 |
|---|---|---|---|
designId | string (UUID) | ✓ | デザインID(パスパラメータ) |
version | integer | - | バージョン番号(クエリパラメータ、省略時は最新) |
レスポンス
成功時 (200 OK)
{
"customerName": "string",
"invoiceNumber": "string",
"amount": "number",
"items": [
{
"name": "string",
"price": "number",
"quantity": "number"
}
],
"issueDate": "date"
}
フィールドの型:
| 型 | 説明 | 例 |
|---|---|---|
string | 文字列 | "山田太郎" |
number | 数値 | 1000 |
date | 日付(ISO 8601) | "2024-02-12" |
object | ネストしたオブジェクト | { "name": "値" } |
array | 配列 | [{ "item": 1 }] |
エラー時
404 Not Found
{
"statusCode": 404,
"message": "Design not found",
"error": "Not Found"
}
原因: 指定されたデザインIDまたはバージョンが存在しない
ユースケース
動的フォーム生成
デザインパラメータから入力フォームを動的に生成する例。
async function createDynamicForm(designId) {
// パラメータスキーマを取得
const schema = await getDesignParameters(designId);
// スキーマからフォームフィールドを生成
const formFields = Object.entries(schema).map(([key, type]) => {
if (type === 'string') {
return `<input type="text" name="${key}" placeholder="${key}" />`;
} else if (type === 'number') {
return `<input type="number" name="${key}" placeholder="${key}" />`;
} else if (type === 'date') {
return `<input type="date" name="${key}" />`;
} else if (Array.isArray(type)) {
// 配列型の場合
return `<div id="${key}-array"><!-- 配列入力 --></div>`;
}
});
return formFields.join('\n');
}
バリデーション
function validateParams(params, schema) {
const errors = [];
for (const [key, type] of Object.entries(schema)) {
if (!(key in params)) {
errors.push(`必須パラメータ ${key} が不足しています`);
continue;
}
const value = params[key];
if (type === 'string' && typeof value !== 'string') {
errors.push(`${key} は文字列である必要があります`);
} else if (type === 'number' && typeof value !== 'number') {
errors.push(`${key} は数値である必要があります`);
} else if (type === 'date') {
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) {
errors.push(`${key} はISO 8601形式の日付である必要があります`);
}
}
}
return errors;
}
// 使用例
const schema = await getDesignParameters('550e8400-...');
const params = {
customerName: '山田太郎',
invoiceNumber: 'INV-001',
amount: 10000
};
const errors = validateParams(params, schema);
if (errors.length > 0) {
console.error('バリデーションエラー:', errors);
}
ベストプラクティス
1. パラメータスキーマのキャッシュ
デザインのバージョンが変わらない限り、パラメータスキーマは変わりません。キャッシュして再利用することを推奨します。
const schemaCache = new Map();
async function getDesignParametersCached(designId, version) {
const cacheKey = `${designId}:${version}`;
if (schemaCache.has(cacheKey)) {
return schemaCache.get(cacheKey);
}
const schema = await getDesignParameters(designId, version);
schemaCache.set(cacheKey, schema);
return schema;
}
2. PDF生成前の検証
パラメータスキーマを事前に取得してバリデーションを行うことで、エラーを早期に検出できます。
async function generatePDFSafely(params) {
// 1. パラメータスキーマを取得
const schema = await getDesignParameters(params.designId, params.version);
// 2. バリデーション
const errors = validateParams(params.data, schema);
if (errors.length > 0) {
throw new Error(`パラメータエラー: ${errors.join(', ')}`);
}
// 3. PDF生成
return await generatePDF(params);
}