Documentation
API Documentation
Learn how to integrate Templyze's document generation API into your applications.
Getting Started
Base URL
All API requests should be made to:
https://api.templyze.com/v1
Quick Start
Get started with the Templyze API in just a few steps:
- Sign up for a Templyze account
- Generate an API key in your dashboard
- Make your first API call
- Start generating documents!
Authentication
Templyze uses API keys to authenticate requests. Include
your API key in the
X-API-Key header:
X-API-Key: YOUR_API_KEY
Keep your API keys secure and never expose them in client-side code. API keys should only be used in server-side applications.
Generate Documents
POST /api/public/v1/generate (Public API)
Generate documents from external systems. Upload template files or use saved template IDs.
Supported Output Formats: xlsx, pdf, png, jpg
POST /api/public/v1/generate
X-API-Key: YOUR_API_KEY
Content-Type: multipart/form-data
# Generate with template file (Free plan)
template: [XLSX template file]
data: {"customer":"Acme Corp","items":[{"name":"Product A","price":100,"qty":2}]}
outputFormat: xlsx
filename: invoice_001
# Or generate with saved template (Paid plans)
templateId: template_123
data: {"customer":"Acme Corp","items":[{"name":"Product A","price":100,"qty":2}]}
outputFormat: pdf
filename: invoice_001
Template Management
Available for Starter plans and above.
Upload Template
POST /api/v1/templates/upload
X-API-Key: YOUR_API_KEY
Content-Type: multipart/form-data
template: [XLSX template file]
name: "Invoice Template"
description: "Monthly invoice template"
category: "finance"
tags: "invoice,billing"
sampleData: {"customer":"Test Corp","amount":100}
List Templates
GET /api/v1/templates/list
X-API-Key: YOUR_API_KEY
Get Template Details
GET /api/v1/templates/{templateId}
X-API-Key: YOUR_API_KEY
Update Template Metadata
PUT /api/v1/templates/{templateId}
X-API-Key: YOUR_API_KEY
Content-Type: application/json
{
"name": "Updated Invoice Template",
"description": "Updated description",
"tags": ["invoice", "billing", "updated"],
"isPublic": false
}
Delete Template
DELETE /api/v1/templates/{templateId}
X-API-Key: YOUR_API_KEY
Download Template File
GET /api/v1/templates/{templateId}/download
X-API-Key: YOUR_API_KEY
Additional Features
Batch Processing (Business+ Plans)
Generate multiple documents at once using batch processing.
POST /api/v1/batch/jobs
X-API-Key: YOUR_API_KEY
Content-Type: application/json
{
"templateId": "template_123",
"items": [
{
"filename": "invoice_001",
"data": {"customer": "Customer A", "amount": 100}
},
{
"filename": "invoice_002",
"data": {"customer": "Customer B", "amount": 200}
}
],
"outputFormat": "pdf"
}
Webhooks (Enterprise Plan)
Receive automatic notifications when document generation is completed.
POST /api/v1/webhooks
X-API-Key: YOUR_API_KEY
Content-Type: application/json
{
"url": "https://your-app.com/webhook",
"events": ["document.generated", "batch.completed"],
"active": true
}
Storage Management
List and manage generated files in your storage.
# List generated files
GET /api/v1/storage/files
X-API-Key: YOUR_API_KEY
# Generate shareable URL
POST /api/v1/storage/share
X-API-Key: YOUR_API_KEY
Content-Type: application/json
{
"fileName": "generated_file.xlsx",
"expirationHours": 24
}
API Reference
Generate Document
Generate a document by uploading a template file or using a saved template ID.
Request Body (multipart/form-data)
| Parameter | Type | Required | Description |
|---|---|---|---|
template
|
file | conditional | Excel template file (.xlsx) |
templateId
|
string | conditional | Saved template ID |
data
|
string | yes | JSON data as string |
outputFormat
|
string | no | xlsx, pdf, png, jpg (default: xlsx) |
filename
|
string | no | Generated file name |
Example Request
curl -X POST https://api.templyze.com/v1/api/public/v1/generate \
-H "X-API-Key: YOUR_API_KEY" \
-F "template=@invoice_template.xlsx" \
-F 'data={"customer":"Acme Corp","amount":1500}' \
-F "outputFormat=pdf"
Example Response
{
"success": true,
"data": {
"downloadUrl": "https://storage.googleapis.com/...",
"filename": "invoice_001.pdf",
"fileSize": 1024000,
"mimeType": "application/pdf",
"processingTime": 1500
}
}
List Templates
Retrieve a list of available gallery templates.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
category
|
string | Filter by category |
limit
|
integer | Number of results (default: 20) |
Code Examples
JavaScript (Node.js)
const FormData = require('form-data');
const fetch = require('node-fetch');
const fs = require('fs');
async function generateDocument() {
const form = new FormData();
form.append('template', fs.createReadStream('invoice.xlsx'));
form.append('data', JSON.stringify({
customer: 'Acme Corp',
items: [
{ name: 'Product A', price: 100, qty: 2 },
{ name: 'Product B', price: 50, qty: 1 }
],
total: 250
}));
form.append('outputFormat', 'pdf');
const response = await fetch('https://api.templyze.com/v1/api/public/v1/generate', {
method: 'POST',
headers: {
'X-API-Key': 'YOUR_API_KEY',
...form.getHeaders()
},
body: form
});
const result = await response.json();
console.log('Generated document:', result.data.downloadUrl);
}
Python
import requests
import json
def generate_document():
url = 'https://api.templyze.com/v1/api/public/v1/generate'
headers = {
'X-API-Key': 'YOUR_API_KEY'
}
data = {
'customer': 'Acme Corp',
'items': [
{'name': 'Product A', 'price': 100, 'qty': 2},
{'name': 'Product B', 'price': 50, 'qty': 1}
],
'total': 250
}
files = {
'template': open('invoice.xlsx', 'rb'),
'data': (None, json.dumps(data)),
'outputFormat': (None, 'pdf')
}
response = requests.post(url, headers=headers, files=files)
result = response.json()
print(f"Generated document: {result['data']['downloadUrl']}")
generate_document()
PHP
'Acme Corp',
'items' => array(
array('name' => 'Product A', 'price' => 100, 'qty' => 2),
array('name' => 'Product B', 'price' => 50, 'qty' => 1)
),
'total' => 250
);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.templyze.com/v1/api/public/v1/generate',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array(
'template' => new CURLFile('invoice.xlsx'),
'data' => json_encode($data),
'outputFormat' => 'pdf'
),
CURLOPT_HTTPHEADER => array(
'X-API-Key: YOUR_API_KEY'
),
));
$response = curl_exec($curl);
$result = json_decode($response, true);
echo "Generated document: " . $result['data']['downloadUrl'];
curl_close($curl);
?>
Error Handling
HTTP Status Codes
| Code | Description |
|---|---|
| 200 | Success |
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid API key |
| 403 | Forbidden - API key disabled |
| 429 | Rate limit exceeded |
| 500 | Internal server error |
Error Response Format
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"statusCode": 400,
"details": [
{
"field": "data",
"message": "Data is required"
}
]
}
}
Rate Limits
API rate limits vary by subscription plan:
| Plan | Daily Requests | Processing Units |
|---|---|---|
| Free | 100/day | 100/month |
| Professional | 1,000/day | 1,500/month |
| Business | 5,000/day | 5,000/month |
| Enterprise | Unlimited | 20,000/month |
Check the response headers for rate limit information:
X-RateLimit-Limit,
X-RateLimit-Remaining,
X-RateLimit-Reset
Webhooks
Webhooks allow you to receive real-time notifications when events occur in your Templyze account.
Supported Events
-
document.generated- Document generation completed -
document.failed- Document generation failed -
batch.completed- Batch job completed -
usage.limit_reached- Usage limit reached
Webhook Payload Example
{
"id": "evt_1234567890",
"type": "document.generated",
"created": "2024-01-15T10:30:00Z",
"data": {
"object": {
"id": "doc_abcdef123456",
"status": "completed",
"downloadUrl": "https://storage.googleapis.com/...",
"processingTime": 1500,
"fileSize": 1024000
}
}
}