---
title: "generateDocument"
method: POST
path: "/v1/journey/document:generate"
tags: ["Journeys"]
---

# generateDocument

`POST /v1/journey/document:generate`

Builds document generated from a template with journey values."

Supported input document types:
- .docx

Supported output document types:
- .pdf
- .docx but limited to only text based variables

Uses [Document API](https://gitlab.com/e-pilot/product/file-management/document-api) to generate the document.
Uses [Template Variables API](https://docs.epilot.io/api/template-variables) to replace variables in the document.

## Request body

- GenerateDocumentRequest
  - `file_id` string, required — Entity id for the template being used
  - `context_data` object, required — Custom values for variables in the template. Takes the higher precedence than others.
    - `additionalProperties` string
  - `context_entity_id` string, uuid — Entity id used to resolve entity and relational template variables
  - `language` string — Language code for the document

## Response `200`

Generated document output

- GenerateDocumentResponse
  - `job_id` string, uuid
  - `job_status` 'STARTED' | 'PROCESSING' | 'SUCCESS' | 'FAILED' — Status of the job
  - `message` string — A message explaining the progress
  - `pdf_output` object
    - `preview_url` string — Pre-signed S3 GET URL for PDF preview
    - `output_document` object
      - `filename` string — Generated document filename for PDF
      - `s3ref` S3Reference
        - `bucket` string, required
        - `key` string, required
  - `docx_output` object
    - `preview_url` string — Pre-signed S3 GET URL for DOCX preview
    - `output_document` object
      - `filename` string — Generated document filename for DOCX
      - `s3ref` S3Reference
        - `bucket` string, required
        - `key` string, required
  - `variable_payload` object — List of variables and its corresponding replaced values from the document template
    - `additionalProperties` string
  - `template_settings` TemplateSettings — Template Settings for document generation
    - `custom_margins` object — Custom margins for the document
      - `top` number — Top margin in cm
      - `bottom` number — Bottom margin in cm
    - `suggested_margins` object — Suggested margins for the document
      - `top` number — Top margin in cm
      - `bottom` number — Bottom margin in cm
    - `display_margin_guidelines` boolean — Display margin guidelines (applicable to partial generation only)
    - `enable_data_table_margin_autofix` boolean — Enable data table margin autofix
    - `template_with_datatable` boolean — A flag that indicates whether the template has 1 or more data tables in it
    - `enabled_template_settings_persistence` boolean — Enables the persistance of template settings
    - `misconfigured_margins` boolean — An indication that the page margins are misconfigured
    - `file_entity_id` string, uuid — The file entity id, used when persisting a new template version with updated settings

---

[API](https://skmtc.net/epilot/apis/journey-api.md) · [All operations](https://skmtc.net/epilot/apis/journey-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/epilot/journey-api/versions/515acb1f892e/schema)
