---
title: "Expose Typst template data"
method: GET
path: "/leases/{lease_id}/template-data"
tags: ["Leases"]
---

# Expose Typst template data

`GET /leases/{lease_id}/template-data`

## Request

- Base URL: `https://api.faireplace.com/api`
- URL: `https://api.faireplace.com/api/leases/{lease_id}/template-data`
- Auth: HTTP bearer

Retrieves all data needed to generate a Typst document for a given lease.
The data is converted from TypstDict format to JSON and exposed with metadata.

This endpoint also allows passing custom variables via query parameters.
These variables will be integrated into the template data before JSON conversion.

**Use cases:**
- Custom PDF document generation
- Data preview before generation
- Integration with external systems
- Debug and validation of template data

## Path parameters

- `lease_id` string, uuid, required

## Query parameters

- `customVariables` object

## Response `200`

Template data exposed successfully.

The response contains:
- `lease_id`: Lease ID
- `template_data`: Complete data in JSON format (lease, property, owner, tenants, charges, etc.)
- `metadata`: Metadata about the generation (processing time, data size, etc.)

- LeaseTemplateDataResponse: Response containing Typst template data exposed in JSON format. This response is generated by the `/leases/{lease_id}/template-data` endpoint and contains all the data needed to generate a Typst document for a given lease. The data includes: - Lease information (amount, dates, status, etc.) - Property details (address, area, etc.) - Owner information - List of lessees and their details - Charges associated with the lease - Custom variables (if provided via query parameters) - Generation metadata **Data structure:** - `lease_id`: Lease identifier - `template_data`: JSON object containing all structured data - `metadata`: Generation metadata (time, size, etc.)
  - `lease_id` string, uuid, required: Unique identifier of the lease
  - `template_data` object, required: Complete template data in JSON format. This structure contains all the information needed to generate a Typst document, organized hierarchically: **Typical structure:** ```json { "lease": { "id": "uuid", "rent_amount": 1200.00, "status": "ACTIVE", "start_date": "2024-01-01", "end_date": "2024-12-31" }, "estate": { "name": "Appartement T3", "area": 75.5, "address": "123 Rue de la Paix" }, "owner": { "name": "Jean Dupont", "email": "jean@example.com" }, "lessees": [ { "name": "Marie Martin", "email": "marie@example.com" } ], "charges": [ { "name": "Common charges", "amount": 150.00 } ], "custom_variables": { "custom_field": "value", "amount": 123.45 } } ``` **Note:** The exact structure may vary depending on the lease type and available data. Custom variables are added at the root level of `template_data`.
  - `metadata` TemplateDataMetadata, required: Metadata about the template data generation
    - `generated_at` string, date-time, required: Date and time of data generation
    - `generation_time_ms` integer, required: Generation time in milliseconds
    - `has_custom_variables` boolean, required: Indicates whether custom variables have been included
    - `data_schema_version` string, required: Version of the data schema used
    - `data_source` 'database' | 'cache' | 'mock' | 'external', required: Data source (database, cache, mock, etc.)
    - `data_size_bytes` integer, required: Approximate size of the JSON data in bytes

## Other responses

- `400`: Invalid request. May occur if: - The query parameters are malformed - The custom variables cannot be parsed
- `401`: Unauthorized
- `403`: Access denied. The user does not have the necessary permissions to: - Read lease data (`leases:read`) - Access property information - View tenant data
- `404`: Lease not found. The specified lease does not exist or does not belong to the user's tenant.
- `422`: Data processing error. May occur if: - The lease data is incomplete or corrupted - Relationships with other entities (property, owner, tenants) are broken - The TypstDict to JSON conversion fails
- `500`: Internal server error. May occur if: - Database connection issue - Error in the template data repository - Memory issue when processing large volumes of data

---

[API](https://skmtc.dev/faireplace/apis/faireplace-property-management-api.md) · [All operations](https://skmtc.dev/faireplace/apis/faireplace-property-management-api/llms.txt) · [OpenAPI document](https://skmtc.dev/faireplace/apis/faireplace-property-management-api/revisions/69de39762919?raw)
