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

HeaderRequiredValue
X-KeyYesCompany API key
Content-TypeYesapplication/json

Body (JSON)

FieldTypeRequiredDescription
templateIdstringYesThe ID of the template to use for document generation.
dataanyYesArbitrary key-value data to merge into the template. See the Template Library for individual schema definitions.
format"pdf" | "docx"YesThe desired output format.
versionstringNoA specific template version to use. Defaults to the template's latest version.
custombooleanNoWhen 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.

HeaderValue
Content-Typeapplication/pdf or application/vnd.openxmlformats-officedocument.wordprocessingml.document

Error Responses

  • 400 Bad Request: Validation error (e.g., the data payload is missing required schema fields).
  • 401 Unauthorized: Missing or invalid X-Key.
  • 404 Not Found: The requested templateId does not exist.
// Example 400 Validation Error
{
  "error": "validation_error",
  "message": "Data payload does not match template schema",
  "details": {
    "missing_fields": ["effectiveDate"]
  }
}