Skip to content

Create Document From Template

POST
/api/writing/templates/{template_id}/create-document

📝 Create document from template

Creates a new document by instantiating a template with specific variable values. Variables in the template (e.g., {{character_name}}) are replaced with the provided values to generate a customized document.

Path Parameters:

  • template_id: ID of the template to use

Request Body:

  • title: Title for the new document
  • variables: Dictionary of variable substitutions (e.g., {“name”: “Aragorn”})

Dependencies:

  • writing_service: Injected IshvanaWritingModule instance

Returns:

  • DocumentResponse with the newly created document

Raises:

  • HTTPException 404: If template not found
  • HTTPException 500: If document creation fails

Example Request:

{
    "title": "Aragorn Character Profile",
    "variables": {
        "character_name": "Aragorn",
        "age": "87",
        "race": "Human"
    }
}
template_id
required
Template Id
string
DocumentFromTemplateRequest

Document creation from template request model.

Request model for creating a new document by instantiating a template with specific variable values.

Fields: title: Title for the new document variables: Variable substitution values (e.g., {“character_name”: “Valko”})

Used By: - POST /api/writing/templates/{template_id}/create endpoint - Template instantiation UI - Batch document generation from templates

object
title
required
Title
string
variables
Any of:
object
key
additional properties
string

Successful Response

DocumentResponse

Single document response model.

Response containing a single document with its complete metadata.

Fields: status: Response status (“success”, “error”) document: Complete document metadata

Used By: - GET /api/writing/documents/{document_id} endpoint - Document retrieval operations - Document editor initialization

object
status
required
Status
string
document
required
DocumentMetadata

Document metadata model for writing documents.

Comprehensive metadata model for all writing documents including creative writing, lore entries, worldbuilding documents, and general notes. Uses IshvanaBaseModel for automatic snake_case → camelCase JSON conversion.

Fields: document_id: Unique document identifier project_id: Owning project ID (empty string for unscoped documents) title: Document title document_type: Type classification (lore, character, location, general) tags: Categorization and search tags created_at: Creation timestamp (auto-generated) updated_at: Last modification timestamp (auto-generated) version: Current version number (increments on each update) word_count: Total word count for writing metrics custom_fields: User-defined custom metadata folder_id: Containing folder ID, None for top-level is_fork_branch: Whether this document is a fork branch off a root

Used By: - DocumentListResponse for document listings - DocumentResponse for single document retrieval - AdvancedSearchResponse for search results - Document browser and editor UI - Version history tracking

object
documentId
required
Documentid
string
title
required
Title
string
documentType
required
Documenttype
string
version
required
Version
integer
wordCount
required
Wordcount
integer
projectId
Projectid
string
""
tags
Tags
Array<string>
createdAt
Createdat

Document creation timestamp

string format: date-time
updatedAt
Updatedat

Last update timestamp

string format: date-time
customFields
Customfields
object
key
additional properties
string
folderId
Any of:
string
isForkBranch
Isforkbranch
boolean
status
Status
string
default: active
deletedAt
Any of:
string format: date-time
message
Any of:
string
code
Any of:
integer

Validation Error

HTTPValidationError
object
detail
Detail
Array<object>
ValidationError
object
loc
required
Location
Array
msg
required
Message
string
type
required
Error Type
string
input
Input
ctx
Context
object