Sync Single PDF Generation
The POST /file/sync/single endpoint generates a single PDF file synchronously from the specified design and parameters.
Endpoint Information
- URL:
https://{workspaceId}.re-port-flow.com/v1/file/sync/single - Method:
POST - Authentication: Requires AppKey and SecretKey
- Timeout: 30 seconds
- Request Size Limit: 20MB
Usage Examples
cURL
curl -X POST https://your-workspace-id.re-port-flow.com/v1/file/sync/single \
-H "AppKey: your-app-key" \
-H "SecretKey: your-secret-key" \
-H "Content-Type: application/json" \
-d '{
"designId": "550e8400-e29b-41d4-a716-446655440000",
"version": 1,
"content": {
"fileName": "invoice.pdf",
"params": {
"customerName": "John Doe",
"invoiceNumber": "INV-2024-001",
"amount": 10000
}
}
}' \
--output invoice.pdf
JavaScript (Node.js)
const axios = require('axios');
const fs = require('fs');
async function generatePDF(params) {
try {
const response = await axios.post(
`https://${process.env.WORKSPACE_ID}.re-port-flow.com/v1/file/sync/single`,
{
designId: params.designId,
version: params.version,
content: {
fileName: params.fileName,
params: params.data
}
},
{
headers: {
'AppKey': process.env.APP_KEY,
'SecretKey': process.env.SECRET_KEY,
'Content-Type': 'application/json'
},
responseType: 'arraybuffer'
}
);
// Save to file
fs.writeFileSync(params.fileName, response.data);
// Get response headers
const fileUrl = response.headers['file-url'];
const fileId = response.headers['file-id'];
console.log('PDF generated successfully:', { fileUrl, fileId });
return { data: response.data, fileUrl, fileId };
} catch (error) {
console.error('PDF generation error:', error.response?.data || error.message);
throw error;
}
}
// Usage example
generatePDF({
designId: '550e8400-e29b-41d4-a716-446655440000',
version: 1,
fileName: 'invoice.pdf',
data: {
customerName: 'John Doe',
invoiceNumber: 'INV-2024-001',
amount: 10000
}
});
Python
import requests
def generate_pdf(params):
url = f"https://{params['workspace_id']}.re-port-flow.com/v1/file/sync/single"
headers = {
'AppKey': params['app_key'],
'SecretKey': params['secret_key'],
'Content-Type': 'application/json'
}
data = {
'designId': params['design_id'],
'version': params['version'],
'content': {
'fileName': params['file_name'],
'params': params['data']
}
}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
# Save to file
with open(params['file_name'], 'wb') as f:
f.write(response.content)
# Get response headers
file_url = response.headers.get('file-url')
file_id = response.headers.get('file-id')
return {'file_url': file_url, 'file_id': file_id}
# Usage example
result = generate_pdf({
'workspace_id': 'your-workspace-id',
'app_key': 'your-app-key',
'secret_key': 'your-secret-key',
'design_id': '550e8400-e29b-41d4-a716-446655440000',
'version': 1,
'file_name': 'invoice.pdf',
'data': {
'customerName': 'John Doe',
'invoiceNumber': 'INV-2024-001',
'amount': 10000
}
})
Request Parameters
| Field | Type | Required | Description |
|---|---|---|---|
designId | string (UUID) | ✓ | Design ID |
version | integer | ✓ | Version number |
content.fileName | string | ✓ | File name (alphanumeric, Japanese, -, _, . only) |
content.params | object | ✓ | Parameters to embed in template (check structure via Design Parameters API) |
Response
Success (200 OK)
Response Body: PDF file (binary)
Response Headers:
| Header | Description | Example |
|---|---|---|
Content-Type | Content type | application/pdf |
Content-Disposition | File name | attachment; filename="invoice.pdf" |
File-URL | File URL | https://re-port-flow.com/workspace-id/design/design-id/files/file-uuid |
File-ID | File ID | file_abc123 |
Errors
400 Bad Request
{
"statusCode": 400,
"message": [
"designId must be a UUID",
"fileName can only contain alphanumeric, Japanese, hyphens, underscores, and dots"
],
"error": "Bad Request"
}
Cause: Invalid request parameters
Solution:
- Verify
designIdis in UUID format - Verify
fileNamematches regex^[a-zA-Z0-9\u3000-\uFFEF_.\-]+$
401 Unauthorized
{
"statusCode": 401,
"message": "Unauthorized",
"error": "Unauthorized"
}
Cause: Authentication error
Solution:
- Verify
AppKeyandSecretKeyare correct - Verify workspace ID matches subdomain
500 Internal Server Error
{
"statusCode": 500,
"message": "Internal server error",
"error": "Internal Server Error"
}
Cause: Server-side error
Solution:
- May be temporary, try retrying
- Contact support if it persists
Best Practices
1. Timeout Handling
Synchronous API times out after 30 seconds. For large PDFs or complex designs, consider using async API.
const response = await axios.post(url, data, {
timeout: 30000 // 30 seconds
});
2. Retry Logic
For temporary server errors (5xx), implement retry with exponential backoff.
async function generatePDFWithRetry(params, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await generatePDF(params);
} catch (error) {
if (error.response?.status === 500 && i < maxRetries - 1) {
const delay = 1000 * Math.pow(2, i);
await new Promise(resolve => setTimeout(resolve, delay));
continue;
}
throw error;
}
}
}
3. File Name Sanitization
function sanitizeFileName(fileName) {
return fileName.replace(/[^a-zA-Z0-9\u3000-\uFFEF_.\-]/g, '_');
}
Use Cases
Case 1: Instant Invoice Generation
Generate and download PDF instantly when user clicks "Download Invoice" button.
app.get('/api/invoices/:id/download', async (req, res) => {
const invoice = await getInvoice(req.params.id);
const pdf = await generatePDF({
designId: 'invoice-template-id',
version: 1,
fileName: `invoice_${invoice.number}.pdf`,
data: invoice
});
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', `attachment; filename="invoice_${invoice.number}.pdf"`);
res.send(pdf.data);
});
Case 2: Preview Generation
Generate PDF in real-time when user clicks preview button in design editor.
async function showPreview(designId, params) {
const pdf = await generatePDF({
designId,
version: 1,
fileName: 'preview.pdf',
data: params
});
// Display PDF in browser
const blob = new Blob([pdf.data], { type: 'application/pdf' });
const url = URL.createObjectURL(blob);
window.open(url, '_blank');
}
Next Steps
- Async Single PDF - To avoid timeout
- Sync Multiple PDFs - Generate multiple PDFs at once
- Async Workflows - Best practices for bulk generation