Documentation
Home Documentation

Overview

DigiDoc is a document generation API that takes DOCX templates with variables and renders them into finalized PDF or DOCX documents.

Creating Templates

Templates are standard .docx files created in Word, Google Docs, or LibreOffice. Insert placeholders using docxtpl (Jinja2) syntax. See the docxtpl documentation for advanced features.

Basic Variables

Wrap variable names in double curly braces:

{# In your DOCX, type: #}
{{ customer_name }}
{{ invoice_date }}
{{ total_amount }}

Example data:

{
    "customer_name": "Acme Corp",
    "invoice_date": "June 17, 2026",
    "total_amount": "$1,250.00"
}

Loops (Tables & Lists)

Use {% for %} to repeat sections — great for invoice line items:

{# Select the table row and wrap it: #}
{% for item in items %}
{{ item.name }}    {{ item.quantity }}    {{ item.price }}
{% endfor %}

Example data:

{
    "items": [
        { "name": "Widget", "qty": "2", "price": "$10" },
        { "name": "Gadget", "qty": "1", "price": "$25" }
    ]
}
Tip: To repeat a table row, select the entire row in Word and wrap it with {% for item in items %} and {% endfor %}.

Conditionals

{% if show_discount %}
Discount: {{ discount_amount }}
{% endif %}

Images in Templates

Images can be injected dynamically. Three ways to reference them:

Storage Images (Recommended)

Upload an image in the admin panel, then reference it by name or ID:

{
    "company_logo": "storage::MyLogoName"
}

The storage:: prefix tells DigiDoc to look up the image from your library.

Base64 with Custom Size

{
    "photo": {
        "data": "iVBORw0KGgoAAAANSUhEUg...",
        "width": 100,
        "height": 50,
        "unit": "mm"
    }
}

Units: mm (default), inches, pt.

Data URI

{
    "photo": "data:image/png;base64,iVBORw0KGgo..."
}

Images in Loops

Nested images work inside {% for %} loops too:

{
    "products": [
        { "name": "Widget", "thumb": "storage::widget_thumb" },
        { "name": "Gadget", "thumb": "storage::gadget_thumb" }
    ]
}

API Usage

All API endpoints require an X-API-Key header. Generate a key from API Keys.

List Templates

GET/api/v1/templates
curl -H "X-API-Key: df_your_key_here" API_BASE_URL/api/v1/templates

Upload Template

POST/api/v1/templates
ParamTypeDescription
fileFilerequiredThe .docx file
nameStringoptionalCustom alias
category_idStringoptionalCategory UUID
curl -X POST -H "X-API-Key: df_your_key_here" \
  -F "file=@invoice.docx" \
  -F "name=My Invoice" \
  -F "category_id=YOUR_CATEGORY_UUID" \
  API_BASE_URL/api/v1/templates
Workspace: The API key's workspace is automatically assigned — templates are scoped to that workspace.

Render Document

POST/api/v1/render
ParamTypeDescription
template_idStringopt*Registered template ID
template_nameStringopt*Registered template name
templateFileopt*Upload file directly
dataJSONrequiredTemplate variables as JSON string
output_formatStringoptionalDefault: docx

* Provide exactly one of template_id, template_name, or template file.

# By template ID
curl -X POST -H "X-API-Key: df_your_key_here" \
  -F "template_id=abc-123-def" \
  -F 'data={"customer":"Acme Corp"}' \
  -F "output_format=pdf" \
  API_BASE_URL/api/v1/render --output invoice.pdf

# By template name
curl -X POST -H "X-API-Key: df_your_key_here" \
  -F "template_name=My Invoice" \
  -F 'data={"customer":"Acme Corp"}' \
  -F "output_format=pdf" \
  API_BASE_URL/api/v1/render --output invoice.pdf

# Upload template file directly
curl -X POST -H "X-API-Key: df_your_key_here" \
  -F "template=@invoice.docx" \
  -F 'data={"customer":"Acme Corp"}' \
  -F "output_format=pdf" \
  API_BASE_URL/api/v1/render --output invoice.pdf

List Images

GET/api/v1/images
curl -H "X-API-Key: df_your_key_here" API_BASE_URL/api/v1/images

List Categories

GET/api/v1/categories

Returns categories associated with your API key's workspace — no query params needed.

curl -H "X-API-Key: df_your_key_here" API_BASE_URL/api/v1/categories

Upload Image

POST/api/v1/images
ParamTypeDescription
fileFilerequiredThe image file
nameStringoptionalCustom alias
category_idStringoptionalCategory UUID
curl -X POST -H "X-API-Key: df_your_key_here" \
  -F "file=@logo.png" \
  -F "name=Company Logo" \
  -F "category_id=YOUR_CATEGORY_UUID" \
  API_BASE_URL/api/v1/images
Workspace: The API key's workspace is automatically assigned — images are scoped to that workspace.

Output Formats

FormatDescription
docxWord Document
pdfPortable Document Format

API Keys

Keys are associated with your account and scoped to a workspace.

  • Generate keys from API Keysmust select a workspace
  • The key is shown once on creation, and can be revealed later via the eye icon in the keys list (encrypted storage)
  • Toggle active/inactive or delete keys from the admin panel
  • Keys are workspace-scoped: list endpoints only return resources in that workspace, uploads auto-assign it, and render returns 403 on workspace mismatch
  • Rate limit: 10 requests per 60 seconds by default