Document Generation
POST /api/v1/documents/generate
Generates a document (PDF or DOCX) by merging caller-supplied data into a stored template, then returns the raw binary output.
Request
Headers
| Header | Required | Value |
|---|---|---|
X-Key | Yes | Company API key |
Content-Type | Yes | application/json |
Body (JSON)
| Field | Type | Required | Description |
|---|---|---|---|
templateId | string | Yes | The ID of the template to use for document generation. |
data | any | Yes | Arbitrary key-value data to merge into the template. See the Template Library for individual schema definitions. |
format | "pdf" | "docx" | Yes | The desired output format. |
version | string | No | A specific template version to use. Defaults to the template's latest version. |
custom | boolean | No | When true, looks up a company-specific template override instead of the global template. |
Example Requests
cURL
curl -X POST https://api.lawyeredapp.com/v1/documents/generate \
-H "X-Key: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"templateId": "non-disclosure-agreement",
"data": {
"parties": [
{
"isCompany": true,
"rcName": "Acme Corp",
"rcAddress": "123 Beta Way",
"rcCountry": "United States",
"rcNumber": "12345678",
"type": "Private Company limited by shares"
},
{
"isCompany": false,
"fullName": "Joshua",
"address": "789 Alpha Ave",
"rcCountry": "Nigeria"
}
],
"project": "System Architecture Review",
"ndaDuration": "12 months",
"add_non_circumvention_clause": true,
"dispute": true,
"governingLaw": "Nigeria"
},
"format": "pdf"
}
' --output generated_nda.pdf
JavaScript (Fetch)
const response = await fetch('https://api.lawyeredapp.com/v1/documents/generate', {
method: 'POST',
headers: {
'X-Key': '<your-api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
templateId: 'nda-standard',
data: { partyA: 'Acme Corp', partyB: 'Globex Ltd', effectiveDate: '2026-05-01' },
format: 'pdf'
})
});
// Handling the binary response
const blob = await response.blob();
// ... logic to save or stream the blob
Responses
200 OK On success, returns the raw binary content of the generated document. Stream it directly to disk or pipe it to your client.
| Header | Value |
|---|---|
Content-Type | application/pdf or application/vnd.openxmlformats-officedocument.wordprocessingml.document |
Error Responses
400 Bad Request: Validation error (e.g., thedatapayload is missing required schema fields).401 Unauthorized: Missing or invalidX-Key.404 Not Found: The requestedtemplateIddoes not exist.
// Example 400 Validation Error
{
"error": "validation_error",
"message": "Data payload does not match template schema",
"details": {
"missing_fields": ["effectiveDate"]
}
}
