# Update a Word template

https://radiologydictation.com/docs/patch-v1-document-templates-template-id

```http
PATCH /v1/document-templates/{template_id}
```

Edit a saved template’s text, paragraph structure, or report formatting. Read the current template first, then send expected_revision and the changes you want to apply. A successful save creates a new revision and returns its updated paragraph IDs and formatting.

A stale revision returns 409 without applying your changes. Read the latest template and review how to combine the edits before retrying. Paragraph IDs and text offsets must come from the revision you are editing.

## Replace text precisely

edits contains a paragraph id, start, end, and replacement text. Text-edit offsets count Unicode characters; end is exclusive. For example, start 0 and end 5 replace the first five characters. Use equal start and end to insert text, or an empty replacement string to remove selected text. JavaScript string indexes count UTF-16 code units, so convert indexes when text includes characters outside the basic multilingual plane.

## Delete, move, or remove a break

operations can delete eligible paragraphs, move a paragraph before another within its safe move_group, or remove page and column breaks. A move with before_id omitted or null places the paragraph at the end of its group. Break offsets refer to the original revision; page_break_before has no offset. Text edits are applied before structural operations. The whole update is rejected if an operation is invalid.

## Save report formatting

Omitted spacing keeps the saved formatting. A supplied spacing object replaces the formatting options: include the saved values you want to preserve. Blank-paragraph options accept true or false. Bold, underline, italic, and bullet options accept true, false, or null to inherit the template. An omitted option inside a supplied spacing object resets to its default.

Formatting applies to generated Findings and Impression text. Headings, surrounding text, images, and other document formatting retain their existing appearance. The API examples below show formatting-only changes as well as text edits and paragraph operations.

[Working with Word templates](https://radiologydictation.com/docs/word-templates.md)

## Authentication

Create a named API key in your workspace’s API keys tab, then send it in the Authorization header on each API request. Your key connects the integration to that workspace’s saved settings and Word templates. Signing into the website does not replace this header in an API integration.

```http
Authorization: Bearer <API_KEY>
```

Keep the key in your application’s server-side secret configuration. It is shown only once when created, so save it securely then. Do not place it in browser code, logs, version control, or a prompt sent to your coding agent. You can revoke an integration’s key from the workspace without changing the other keys.

## Parameters

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| template_id | path: string | Yes | pattern="^[a-f0-9]{32}$" |  |

## Request

```http
application/json
```

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| expected_revision | integer | Yes | minimum=1.0 | Current revision returned by reading the template. Prevents overwriting another saved edit. |
| edits | array<ParagraphEdit> | No | maxItems=2000 | Text replacements using paragraph IDs and Unicode-character offsets from the expected revision. end is exclusive. |
| operations | array<DeleteParagraph \| MoveParagraph \| RemoveBreak> | No | maxItems=2000 | Ordered paragraph deletions, moves, or page/column break removals applied after text edits. |
| spacing | ReportFormatting \| null | No |  | Report formatting overrides. Omit to preserve saved controls. A supplied object replaces all controls; include values you want to keep. The object cannot be null. |

### Request examples

```json
{
  "expected_revision": 1,
  "spacing": {
    "findings_blank_paragraph": false,
    "findings_bold": true,
    "impression_blank_paragraph": false,
    "impression_bold": true
  }
}
```

```json
{
  "edits": [
    {
      "end": 0,
      "id": "word/document.xml#0",
      "start": 0,
      "text": "{{ exam_title }}"
    }
  ],
  "expected_revision": 1
}
```

```json
{
  "expected_revision": 1,
  "operations": [
    {
      "id": "word/document.xml#1",
      "operation": "delete"
    }
  ]
}
```

```json
{
  "expected_revision": 1,
  "operations": [
    {
      "before_id": "word/document.xml#1",
      "id": "word/document.xml#2",
      "operation": "move"
    }
  ]
}
```

```json
{
  "expected_revision": 1,
  "operations": [
    {
      "id": "word/document.xml#1",
      "kind": "page_break",
      "offset": 12,
      "operation": "remove_break"
    }
  ]
}
```

## Example

```bash
BASE_URL=https://radiologydictation.com

curl --request PATCH "$BASE_URL/v1/document-templates/$TEMPLATE_ID" \
  --header "Authorization: Bearer $API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"expected_revision": 1, "spacing": {"findings_blank_paragraph": false, "findings_bold": true, "impression_blank_paragraph": false, "impression_bold": true}}'
```

## Responses

| Status | Description | Type |
| --- | --- | --- |
| 200 | Successful Response | TemplateDetail · application/json |
| 401 | Invalid or missing API key | object · application/json |
| 429 | Too many attempts. Please try again later. | object · application/json |
| 503 | Service is unavailable. Please try again. | object · application/json |
| 404 | Template not found. | object · application/json |
| 409 | Template changed. Reload it before saving. | object · application/json |
| 413 | Word template exceeds the configured limits. | object · application/json |
| 422 | Invalid Word template. | object · application/json |
| 415 | JSON request required. | object · application/json |

### Response headers · 429

| Header | Type | Description |
| --- | --- | --- |
| Retry-After | string |  |

## Schemas

### DeleteParagraph

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| operation | string | Yes |  |  |
| id | string | Yes | maxLength=200 |  |

### MoveParagraph

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| operation | string | Yes |  |  |
| id | string | Yes | maxLength=200 |  |
| before_id | string \| null | No |  |  |

### Paragraph

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| id | string | Yes |  |  |
| text | string | Yes |  |  |
| editable | boolean | Yes |  |  |
| deletable | boolean | No | default=false |  |
| move_group | string \| null | No |  |  |
| markers | array<ParagraphMarker> | No |  |  |

### ParagraphEdit

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| id | string | Yes | maxLength=200 |  |
| start | integer | Yes | minimum=0.0 |  |
| end | integer | Yes | minimum=0.0 |  |
| text | string | Yes | maxLength=20000 |  |

### ParagraphMarker

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| kind | string | Yes | enum=["page_break", "page_break_before", "column_break", "section_break", "image", "field", "anchor", "table_cell", "protected_structure"] |  |
| position | string | Yes | enum=["before", "within", "after"] |  |
| offset | integer \| null | No |  |  |
| section_type | string \| null | No |  |  |

### RemoveBreak

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| operation | string | Yes |  |  |
| id | string | Yes | maxLength=200 |  |
| kind | string | Yes | enum=["page_break", "column_break", "page_break_before"] |  |
| offset | integer \| null | No |  |  |

### ReportFormatting

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| findings_blank_paragraph | boolean | No | default=false |  |
| impression_blank_paragraph | boolean | No | default=false |  |
| findings_bulleted | boolean \| null | No |  |  |
| impression_bulleted | boolean \| null | No |  |  |
| findings_bold | boolean \| null | No |  |  |
| findings_underline | boolean \| null | No |  |  |
| findings_italic | boolean \| null | No |  |  |
| impression_bold | boolean \| null | No |  |  |
| impression_underline | boolean \| null | No |  |  |
| impression_italic | boolean \| null | No |  |  |

### TemplateDetail

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| id | string | Yes |  |  |
| name | string | Yes |  |  |
| revision | integer | Yes |  |  |
| created_at | string (date-time) | Yes |  |  |
| updated_at | string (date-time) | Yes |  |  |
| paragraphs | array<Paragraph> | Yes |  |  |
| placeholders | array<string> | Yes |  |  |
| spacing | ReportFormatting | No |  |  |
| bulleted_placeholders | array<string> | No |  |  |
| placeholder_formatting | object | No |  |  |

### TemplateUpdate

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| expected_revision | integer | Yes | minimum=1.0 | Current revision returned by reading the template. Prevents overwriting another saved edit. |
| edits | array<ParagraphEdit> | No | maxItems=2000 | Text replacements using paragraph IDs and Unicode-character offsets from the expected revision. end is exclusive. |
| operations | array<DeleteParagraph \| MoveParagraph \| RemoveBreak> | No | maxItems=2000 | Ordered paragraph deletions, moves, or page/column break removals applied after text edits. |
| spacing | ReportFormatting \| null | No |  | Report formatting overrides. Omit to preserve saved controls. A supplied object replaces all controls; include values you want to keep. The object cannot be null. |

### TextFormatting

| Name | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| bold | boolean | No | default=false |  |
| underline | boolean | No | default=false |  |
| italic | boolean | No | default=false |  |
