How to Populate and Update Text Blocks
Dynamically populate or update text blocks in PandaDoc documents via the API, including markdown formatting for rich content.
Problem
You need to dynamically populate or update text blocks in PandaDoc documents via the API. Text blocks support markdown formatting, letting you inject rich content (headings, lists, links, emphasis) into templates at document creation or update time.
Prerequisites
- A PandaDoc template with at least one named text block
- A PandaDoc API key or OAuth token
- Familiarity with the Create Document from Template or Update Document endpoints
Solution
Step 1: Identify text block names in your template
Use the Document Details endpoint to see which text blocks are available:
GET /public/v1/documents/{document_id}/detailsThe response includes a texts array with block names:
{
"texts": [
{
"name": "Legal Terms Section"
},
{
"name": "Product Description"
}
]
}
Thenamemust exactly match an existing text block name in your template.
Step 2: Populate text blocks during document creation
Include a texts array in your create document request. Each entry has a name (matching the template block) and data (the content, with optional markdown):
POST /public/v1/documents
{
"template_uuid": "your-template-id",
"name": "Contract with Custom Terms",
"texts": [
{
"name": "Introduction",
"data": "# Welcome\nThank you for choosing our services."
},
{
"name": "Terms Section",
"data": "## Payment Terms\n- Payment due within **30 days**\n- Late fees apply after grace period"
}
]
}The markdown renders as formatted content in the document:
Step 3: Update text blocks in an existing document
To modify text blocks after creation, send a PATCH request with only the blocks you want to change:
PATCH /public/v1/documents/{document_id}
{
"texts": [
{
"name": "Legal Terms Section",
"data": "## Updated Terms\nThese terms have been revised as of today.\n\n*Please review carefully.*"
}
]
}Supported markdown formatting
The data field supports standard markdown: headings (#), bold (**), italic (*), ordered and unordered lists, links ([text](url)), and blockquotes (>). Use \n for line breaks in JSON strings.
[variable]syntax in markdownText that uses
[variable]syntax will be interpreted as a PandaDoc variable, not as a markdown link. Use full markdown link syntax[text](url)for links.
Text block styles (font, size, color) are preserved from the template -- only the content is replaced.
Verification
- After creating or updating the document, confirm it reaches
document.draftstatus. - Open the document in the PandaDoc web app and verify the text blocks show the expected formatted content.
- Use the Document Details endpoint to verify block names match what you sent.
Related
- Create a Document from Template -- full template-based document creation
- Working with Tables -- managing table content via API
- Update Document API reference -- complete endpoint parameters
Updated about 2 hours ago
