Gen API Quickstart
Generate your first document from a template in under 5 minutes.
Prerequisites
- A Propper account with API access
- API credentials from the dashboard
Step 1: Get an Access Token
Exchange your client credentials for an access token with document generation scopes.
- cURL
- JavaScript
- Python
curl -X POST "https://auth.propper.ai/oauth2/token" \
-H "Content-Type: application/json" \
-d '{
"grant_type": "client_credentials",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"scope": "docgen:read docgen:write"
}'
const getAccessToken = async () => {
const response = await fetch('https://auth.propper.ai/oauth2/token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
grant_type: 'client_credentials',
client_id: process.env.PROPPER_CLIENT_ID,
client_secret: process.env.PROPPER_CLIENT_SECRET,
scope: 'docgen:read docgen:write',
}),
});
const { access_token } = await response.json();
return access_token;
};
const token = await getAccessToken();
import os
import requests
def get_access_token() -> str:
response = requests.post(
"https://auth.propper.ai/oauth2/token",
json={
"grant_type": "client_credentials",
"client_id": os.environ["PROPPER_CLIENT_ID"],
"client_secret": os.environ["PROPPER_CLIENT_SECRET"],
"scope": "docgen:read docgen:write",
},
)
response.raise_for_status()
return response.json()["access_token"]
token = get_access_token()
Response:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "docgen:read docgen:write"
}
tip
Tokens expire in 1 hour. Cache them and refresh before expiry.
Step 2: Create a Template
Create a document template with merge field placeholders.
- cURL
- JavaScript
- Python
curl -X POST "https://api.propper.ai/v1/docgen/templates" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Invoice Template",
"description": "Standard invoice for customers",
"content": "<h1>Invoice</h1><p>Customer: {{customerName}}</p><p>Amount: {{amount}}</p><p>Date: {{date}}</p>",
"format": "HTML"
}'
const createTemplate = async (token) => {
const response = await fetch('https://api.propper.ai/v1/docgen/templates', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Invoice Template',
description: 'Standard invoice for customers',
content:
'<h1>Invoice</h1><p>Customer: {{customerName}}</p><p>Amount: {{amount}}</p><p>Date: {{date}}</p>',
format: 'HTML',
}),
});
return response.json();
};
const template = await createTemplate(token);
console.log('Template ID:', template.id);
def create_template(token: str) -> dict:
response = requests.post(
"https://api.propper.ai/v1/docgen/templates",
headers={
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
},
json={
"name": "Invoice Template",
"description": "Standard invoice for customers",
"content": "<h1>Invoice</h1><p>Customer: {{customerName}}</p><p>Amount: {{amount}}</p><p>Date: {{date}}</p>",
"format": "HTML",
},
)
response.raise_for_status()
return response.json()
template = create_template(token)
print(f"Template ID: {template['id']}")
Response:
{
"id": "tmpl_abc123",
"name": "Invoice Template",
"description": "Standard invoice for customers",
"format": "HTML",
"status": "ACTIVE",
"version": 1,
"createdAt": "2024-01-15T10:00:00Z"
}
Step 3: Generate a Document
Generate a document by providing merge data for the template placeholders.
- cURL
- JavaScript
- Python
curl -X POST "https://api.propper.ai/v1/docgen/documents" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"templateId": "tmpl_abc123",
"mergeData": {
"customerName": "Acme Corp",
"amount": "$1,500.00",
"date": "2024-01-15"
},
"outputFormat": "PDF"
}'
const generateDocument = async (token, templateId) => {
const response = await fetch('https://api.propper.ai/v1/docgen/documents', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
templateId,
mergeData: {
customerName: 'Acme Corp',
amount: '$1,500.00',
date: '2024-01-15',
},
outputFormat: 'PDF',
}),
});
return response.json();
};
const document = await generateDocument(token, template.id);
console.log('Document ID:', document.id);
console.log('Status:', document.status);
def generate_document(token: str, template_id: str) -> dict:
response = requests.post(
"https://api.propper.ai/v1/docgen/documents",
headers={
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
},
json={
"templateId": template_id,
"mergeData": {
"customerName": "Acme Corp",
"amount": "$1,500.00",
"date": "2024-01-15",
},
"outputFormat": "PDF",
},
)
response.raise_for_status()
return response.json()
document = generate_document(token, template["id"])
print(f"Document ID: {document['id']}")
print(f"Status: {document['status']}")
Response:
{
"id": "doc_xyz789",
"templateId": "tmpl_abc123",
"status": "GENERATED",
"outputFormat": "PDF",
"createdAt": "2024-01-15T10:01:00Z"
}
Step 4: Download the Document
Download the generated document.
- cURL
- JavaScript
- Python
curl "https://api.propper.ai/v1/docgen/documents/doc_xyz789/download" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-o invoice.pdf
echo "Downloaded: invoice.pdf"
const downloadDocument = async (token, documentId, outputPath) => {
const response = await fetch(
`https://api.propper.ai/v1/docgen/documents/${documentId}/download`,
{
headers: { Authorization: `Bearer ${token}` },
},
);
const buffer = Buffer.from(await response.arrayBuffer());
const fs = await import('fs/promises');
await fs.writeFile(outputPath, buffer);
console.log(`Downloaded: ${outputPath}`);
};
await downloadDocument(token, document.id, './invoice.pdf');
from pathlib import Path
def download_document(token: str, document_id: str, output_path: str):
response = requests.get(
f"https://api.propper.ai/v1/docgen/documents/{document_id}/download",
headers={"Authorization": f"Bearer {token}"},
)
response.raise_for_status()
Path(output_path).write_bytes(response.content)
print(f"Downloaded: {output_path}")
download_document(token, document["id"], "./invoice.pdf")
Common Mistakes
Don't forget these
1. Missing merge data fields
// Wrong - missing fields referenced in template
{ mergeData: { customerName: 'Acme Corp' } }
// Correct - all template placeholders provided
{ mergeData: { customerName: 'Acme Corp', amount: '$1,500.00', date: '2024-01-15' } }
2. Invalid output format
// Wrong - unsupported format
{ outputFormat: 'DOCX' }
// Correct - supported formats
{ outputFormat: 'PDF' }
{ outputFormat: 'HTML' }
3. Using wrong scope
# Wrong - read scope can't generate documents
scope: "docgen:read"
# Correct - write scope needed for generation
scope: "docgen:read docgen:write"