Templates and Forms
Learn how to create documents from templates and dynamically fill form fields using the sajn API.Overview
Templates in sajn allow you to create reusable document structures with pre-configured form fields. This guide covers:- Creating documents from templates - Use existing templates as document foundation
- Filling form fields - Update form field values using field keys
- Sending templated documents - Complete the workflow by sending for signatures
Template-Based Document Creation
Step 1: Create Document from Template
Create a new document using an existing template as the foundation:Key Parameters
name- Document title (will override template name)templateId- ID of the template to use as foundationtype- Document type (usuallySIGNABLEfor templates)externalId- Optional external reference IDexpiresAt- Optional expiration date
Filling Form Fields
Understanding Field Keys
Templates contain form fields with unique keys that identify each input field. These keys allow you to programmatically update field values. Common field key examples:name- Person’s full namephone- Phone numberemail- Email addressaddress- Street addressstartDate- Employment start date
Step 2: Update Form Fields by Key
Use field keys to update specific form field values:Update Name Field
Update Phone Field
Update Email Field
Field Types and Values
Different field types accept different value formats:Text Input Fields
Number Fields
Date Fields
Checkbox Fields
Select/Dropdown Fields
Complete Workflow Example
Here’s a complete example of creating a document from template, filling fields, and sending for signing:JavaScript Implementation
Step 3: Send for Signing
After filling all form fields, send the document for signatures:Delivery method and signature type are configured per-signer when adding them, not at send time.
Send Options
customMessage- Optional custom message to signers. Supports\nfor line breaks and template variables (e.g.{{firstName}},{{documentName}},{{signUrl}}). See Sending Documents for Signing for the full list.
Advanced Field Operations
Bulk Field Updates
Update multiple FORM fields in a single atomic request with the batch endpointPATCH /documents/{documentId}/fields:
Conditional Field Updates
Update fields based on conditions:Template Field Discovery
Get Template Fields
Discover what fields are available in a template:Extract Field Keys
Error Handling
Common Errors
Field Key Not Found
Invalid Field Value
Template Not Found
Robust Error Handling
Best Practices
1. Field Validation
2. Many Fields (more than 50)
The batch endpoint accepts up to 50 updates per request. If you have more than that, send the chunks sequentially —await each request before the next. Don’t run batch requests for the same document in parallel: they each read-modify-write the same FORM record and would clobber each other, just like parallel single-key calls.
3. Handling Partial Failures
The batch response reports each key individually, so you can surface the ones that failed (e.g. an unknown key) while the valid updates still apply.success is true only when every update in the request succeeded.
Integration Examples
React Form Integration
Node.js Server Integration
Next Steps
- Signer-Fillable Fields - Let signers fill in fields during signing
- Creating Documents - Learn about document creation
- Send for Signing - Complete the signing workflow
- Document Fields API - Single field update reference
- Batch Field Updates API - Update many FORM fields in one request
- File Uploads - Add PDF attachments to templates

