# Edit template design

`opensend.templates.edit(id, input)`

Changes single blocks of a template built from blocks, in place of sending its whole design: add a block, change its fields, its style, its phone style or its dark mode colours, move it, take it out or copy it, or change the style, the dark mode colours, the preview, the fonts or the CSS of the whole message. The operations run in order, and when one is refused nothing is saved. The HTML and the plain text are made from the design again.

Needs the scope: `templates:write`

## Input

`id` goes first, on its own, and the rest in one object. One object that holds `id` works too.

- `id` (string, required): The id of the item. Up to 64 characters.
- `operations` (object[], required): What to change, in order: 1 to 50 operations. Each one works on the design the one before it left, and the design has to hold after each. When one is refused, nothing is saved.
- `operations[].op` (string, required): What to do: `insert` adds a block, `update` changes one, `move` puts one somewhere else, `remove` takes one out with everything inside it, `duplicate` copies one right after itself with new ids, and `page` changes the style, the dark mode colours, the preview, the fonts or the CSS of the whole message. One of: `insert`, `update`, `move`, `remove`, `duplicate`, `page`.
- `operations[].id` (string): For `update`, `move`, `remove` and `duplicate`: the id of the block.
- `operations[].block` (object): For `insert`: the block to add, shaped like a block of the `body` of a design, with `children` when it holds other blocks. Without an `id` it gets one.
- `operations[].block.kind` (string, required): What the block is. `Section`, `Row`, `Column` and `Container` hold other blocks. `Text`, `Heading`, `Button`, `Link`, `Markdown`, `CodeBlock` and `CodeInline` hold text. `Img` is an image, `Hr` a line and `Html` custom code: HTML of your own that goes into the message as it is. One of: `Section`, `Row`, `Column`, `Container`, `Text`, `Heading`, `Button`, `Link`, `Img`, `Hr`, `Markdown`, `CodeBlock`, `CodeInline`, `Html`.
- `operations[].block.id` (string): A name for the block that no other block of the design has: lowercase letters, digits and hyphens. Leave it out and the block gets one.
- `operations[].block.style` (Record<string, string | number>): CSS for the block, by property name, such as `{ "fontSize": "16px", "color": "#111111" }`. Only properties that work in mail are taken.
- `operations[].block.align` (string): Where the block sits across its line: `left`, `center` or `right`. One of: `left`, `center`, `right`.
- `operations[].block.className` (string): Class names for the block, one or several with one space between them, such as `hero wide`, 200 characters at most. The `css` of the design reaches the block by them. A name cannot start with `r-`.
- `operations[].block.only` (string): The one kind of screen the block shows on: `desktop` hides it on a phone, and `phone` shows it on a phone and nowhere else. Without it, the block shows everywhere. One of: `desktop`, `phone`.
- `operations[].block.phone` (Record<string, string | number>): CSS that takes the place of the style of the block on a phone, a screen up to 600 pixels wide, by property name, such as `{ "fontSize": "14px", "padding": "12px" }`. It takes: fontSize, lineHeight, textAlign, padding, paddingTop, paddingRight, paddingBottom, paddingLeft, margin, marginTop, marginRight, marginBottom, marginLeft, width, maxWidth, height.
- `operations[].block.dark` (Record<string, string | number>): Colours that take the place of the ones of the block for a reader in dark mode, by property name, such as `{ "color": "#f4f4f5" }`. It takes: color, backgroundColor, borderColor.
- `operations[].block.text` (string): The words of a block that holds text, up to 20000 characters. `{{NAME}}` marks a variable. A `Markdown` block takes Markdown here, a `CodeBlock` takes the code and an `Html` block takes its HTML, up to 60000 characters.
- `operations[].block.children` (unknown[]): The blocks inside a `Section`, a `Row`, a `Column` or a `Container`, each shaped like a block of `body`. A `Row` takes `Column` blocks only, and a `Column` sits in a `Row` only. Up to 500 items.
- `operations[].block.href` (string): Where a `Button` or a `Link` leads: a full address, or one variable as the whole value, such as `{{URL}}`. Up to 2,048 characters.
- `operations[].block.target` (string): Where the link opens: `_blank` for a new tab or `_self`. Without it, `_blank`. One of: `_blank`, `_self`.
- `operations[].block.src` (string): The address of the picture of an `Img`: a full address, or one variable as the whole value. Up to 2,048 characters.
- `operations[].block.alt` (string): What the picture of an `Img` shows, in words, for someone who cannot see it. Up to 512 characters.
- `operations[].block.width` (string | number): The width of an `Img` or a `Column`: a number of pixels, or a length such as `50%`. Up to 32 characters.
- `operations[].block.height` (string | number): The height of an `Img`: a number of pixels, or a length. Up to 32 characters.
- `operations[].block.valign` (string): Where the content of a `Column` sits: `top`, `middle` or `bottom`. One of: `top`, `middle`, `bottom`.
- `operations[].block.as` (string): The level of a `Heading`, from `h1` to `h6`. Without it, `h1`. One of: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`.
- `operations[].block.language` (string): The language of a `CodeBlock`, such as `typescript` or `bash`. One it does not know is shown as plain text. Up to 64 characters.
- `operations[].block.theme` (string): The colours of a `CodeBlock`: `oneDark`, `oneLight`, `dracula`, `nord`, `vscDarkPlus`, `vs`, `ghcolors` or `materialLight`. Without it, `oneDark`. Up to 64 characters.
- `operations[].block.lineNumbers` (boolean): Whether a `CodeBlock` numbers its lines.
- `operations[].block.stack` (boolean): `true` puts the columns of a `Row` under each other on a phone. Only a `Row` takes it.
- `operations[].parent` (string | null): For `insert` and `move`: the id of the block that takes it, which is a `Section`, a `Row`, a `Column` or a `Container`. Leave it out, or give `null`, for the top level of the message.
- `operations[].index` (integer): For `insert` and `move`: where the block ends up among the blocks of its parent, counted from 0. Leave it out for the end.
- `operations[].set` (object): For `update`: the fields of the block to change, by name. A field set to `null` is taken off the block.
- `operations[].set.align` (string | null): Where the block sits across its line: `left`, `center` or `right`. One of: `left`, `center`, `right`.
- `operations[].set.className` (string | null): Class names for the block, one or several with one space between them, such as `hero wide`, 200 characters at most. The `css` of the design reaches the block by them. A name cannot start with `r-`.
- `operations[].set.only` (string | null): The one kind of screen the block shows on: `desktop` hides it on a phone, and `phone` shows it on a phone and nowhere else. Without it, the block shows everywhere. One of: `desktop`, `phone`.
- `operations[].set.text` (string | null): The words of a block that holds text, up to 20000 characters. `{{NAME}}` marks a variable. A `Markdown` block takes Markdown here, a `CodeBlock` takes the code and an `Html` block takes its HTML, up to 60000 characters.
- `operations[].set.href` (string | null): Where a `Button` or a `Link` leads: a full address, or one variable as the whole value, such as `{{URL}}`. Up to 2,048 characters.
- `operations[].set.target` (string | null): Where the link opens: `_blank` for a new tab or `_self`. Without it, `_blank`. One of: `_blank`, `_self`.
- `operations[].set.src` (string | null): The address of the picture of an `Img`: a full address, or one variable as the whole value. Up to 2,048 characters.
- `operations[].set.alt` (string | null): What the picture of an `Img` shows, in words, for someone who cannot see it. Up to 512 characters.
- `operations[].set.width` (string | number | null): The width of an `Img` or a `Column`: a number of pixels, or a length such as `50%`.
- `operations[].set.height` (string | number | null): The height of an `Img`: a number of pixels, or a length.
- `operations[].set.valign` (string | null): Where the content of a `Column` sits: `top`, `middle` or `bottom`. One of: `top`, `middle`, `bottom`.
- `operations[].set.as` (string | null): The level of a `Heading`, from `h1` to `h6`. Without it, `h1`. One of: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`.
- `operations[].set.language` (string | null): The language of a `CodeBlock`, such as `typescript` or `bash`. One it does not know is shown as plain text. Up to 64 characters.
- `operations[].set.theme` (string | null): The colours of a `CodeBlock`: `oneDark`, `oneLight`, `dracula`, `nord`, `vscDarkPlus`, `vs`, `ghcolors` or `materialLight`. Without it, `oneDark`. Up to 64 characters.
- `operations[].set.lineNumbers` (boolean | null): Whether a `CodeBlock` numbers its lines.
- `operations[].set.stack` (boolean | null): `true` puts the columns of a `Row` under each other on a phone. Only a `Row` takes it.
- `operations[].style` (Record<string, string | number | null>): For `update` and `page`: CSS to merge into the style of the block or of the whole message, by property name. A property set to `null` is taken out.
- `operations[].preview` (string | null): For `page`: the line a mail app shows beside the subject before the message is opened. `null` takes it out. Up to 256 characters.
- `operations[].fonts` (object[] | null): For `page`: the fonts of the message as the whole list, each shaped like a font of a design. `null` takes them all out. Up to 4 items.
- `operations[].fonts[].family` (string, required): The name of the font, such as `Inter`. A block or the page uses the font by naming it in `fontFamily`.
- `operations[].fonts[].fallback` (string, required): The fonts to use where this one does not load, the one you want most first, such as `Helvetica, Arial, sans-serif`. Pick fonts every device has.
- `operations[].fonts[].url` (string, required): The full `https` address of the font file, on your own domain or a CDN. It cannot be a variable. Up to 2,048 characters.
- `operations[].fonts[].format` (string, required): The format of the file: `woff2`, `woff`, `truetype` or `opentype`. One of: `woff2`, `woff`, `truetype`, `opentype`.
- `operations[].fonts[].weight` (number | string): The weight this file holds: a number from 100 to 900 in hundreds, or `normal` or `bold`. Without it, 400.
- `operations[].fonts[].style` (string): The style this file holds: `normal` or `italic`. Without it, `normal`. One of: `normal`, `italic`.
- `operations[].phone` (Record<string, string | number | null>): For `update`: CSS to merge into the phone style of the block, by property name. A property set to `null` is taken out.
- `operations[].dark` (Record<string, string | number | null>): For `update` and `page`: colours to merge into the dark mode colours of the block or of the whole message, by property name. A property set to `null` is taken out.
- `operations[].css` (string | null): For `page`: the CSS of the whole message, as the whole text. `null` takes it out. Up to 20,000 characters.

## Returns

The call resolves to the answer, already parsed. A call the API refuses throws `OpenSendError` with the code and the message of the answer. [SDK](https://opensend.sh/docs/sdk) lists the errors of the client itself.

- `object` ("template"): Always `template`.
- `id` (string): The id of the template.
- `name` (string): The name of the template.
- `alias` (string): A short name of your own to send with in place of the id, such as `welcome`.
- `status` (string): `draft` until it is published, `published` after that. One of: `draft`, `published`.
- `subject` (string): The subject line, as last saved.
- `html` (string): The HTML, as last saved.
- `text` (string | null): The plain text version, as last saved, or `null` when it has none.
- `from` (string): The sender an email built from it gets when the send names none. Empty for none.
- `replyTo` (string): The address replies go to when the send names none. Empty to leave it to the default of the workspace.
- `defaults` (Record<string, string>): A value for a variable, by name, used when a send gives none for it.
- `design` (object | null): The blocks the template is built from, or `null` for a template written as HTML. When it is set, `html` and `text` are made from it.
- `design.preview` (string, optional): The line a mail app shows beside the subject before the message is opened. `{{NAME}}` marks a variable.
- `design.style` (Record<string, string | number>, optional): CSS for the whole message, by property name. A background colour fills the page, a `maxWidth` centres the content, and `fontFamily`, `fontSize` and `lineHeight` are what text gets unless a block sets its own.
- `design.dark` (Record<string, string | number>, optional): Colours for the whole message for a reader in dark mode, by property name: `backgroundColor` fills the page, and `color` and `borderColor` go to the content. It takes: color, backgroundColor, borderColor.
- `design.fonts` (object[], optional): Fonts the message loads from an address of your own, 4 at most. A block or the page uses one by naming its `family` in `fontFamily`, and gets its `fallback` added for the mail apps that load no web fonts.
- `design.fonts[].family` (string): The name of the font, such as `Inter`. A block or the page uses the font by naming it in `fontFamily`.
- `design.fonts[].fallback` (string): The fonts to use where this one does not load, the one you want most first, such as `Helvetica, Arial, sans-serif`. Pick fonts every device has.
- `design.fonts[].url` (string): The full `https` address of the font file, on your own domain or a CDN. It cannot be a variable.
- `design.fonts[].format` (string): The format of the file: `woff2`, `woff`, `truetype` or `opentype`. One of: `woff2`, `woff`, `truetype`, `opentype`.
- `design.fonts[].weight` (number | string, optional): The weight this file holds: a number from 100 to 900 in hundreds, or `normal` or `bold`. Without it, 400.
- `design.fonts[].style` (string, optional): The style this file holds: `normal` or `italic`. Without it, `normal`. One of: `normal`, `italic`.
- `design.css` (string, optional): CSS of your own for the whole message, up to 20000 characters. It goes into the head after the rules the design makes, and reaches a block by its `className`. A rule that has to beat the style a block carries needs `!important`. `</style`, `@import`, `expression(`, `javascript:`, `behavior:`, `-moz-binding` are refused.
- `design.body` (object[]): The blocks of the message, from top to bottom.
- `design.body[].kind` (string): What the block is. `Section`, `Row`, `Column` and `Container` hold other blocks. `Text`, `Heading`, `Button`, `Link`, `Markdown`, `CodeBlock` and `CodeInline` hold text. `Img` is an image, `Hr` a line and `Html` custom code: HTML of your own that goes into the message as it is. One of: `Section`, `Row`, `Column`, `Container`, `Text`, `Heading`, `Button`, `Link`, `Img`, `Hr`, `Markdown`, `CodeBlock`, `CodeInline`, `Html`.
- `design.body[].id` (string): The id of the block. No other block of the design has it.
- `design.body[].style` (Record<string, string | number>, optional): CSS for the block, by property name, such as `{ "fontSize": "16px", "color": "#111111" }`. Only properties that work in mail are taken.
- `design.body[].align` (string, optional): Where the block sits across its line: `left`, `center` or `right`. One of: `left`, `center`, `right`.
- `design.body[].className` (string, optional): Class names for the block, one or several with one space between them, such as `hero wide`, 200 characters at most. The `css` of the design reaches the block by them. A name cannot start with `r-`.
- `design.body[].only` (string, optional): The one kind of screen the block shows on: `desktop` hides it on a phone, and `phone` shows it on a phone and nowhere else. Without it, the block shows everywhere. One of: `desktop`, `phone`.
- `design.body[].phone` (Record<string, string | number>, optional): CSS that takes the place of the style of the block on a phone, a screen up to 600 pixels wide, by property name, such as `{ "fontSize": "14px", "padding": "12px" }`. It takes: fontSize, lineHeight, textAlign, padding, paddingTop, paddingRight, paddingBottom, paddingLeft, margin, marginTop, marginRight, marginBottom, marginLeft, width, maxWidth, height.
- `design.body[].dark` (Record<string, string | number>, optional): Colours that take the place of the ones of the block for a reader in dark mode, by property name, such as `{ "color": "#f4f4f5" }`. It takes: color, backgroundColor, borderColor.
- `design.body[].text` (string, optional): The words of a block that holds text, up to 20000 characters. `{{NAME}}` marks a variable. A `Markdown` block takes Markdown here, a `CodeBlock` takes the code and an `Html` block takes its HTML, up to 60000 characters.
- `design.body[].children` (unknown[], optional): The blocks inside a `Section`, a `Row`, a `Column` or a `Container`, each shaped like a block of `body`. A `Row` takes `Column` blocks only, and a `Column` sits in a `Row` only.
- `design.body[].href` (string, optional): Where a `Button` or a `Link` leads: a full address, or one variable as the whole value, such as `{{URL}}`.
- `design.body[].target` (string, optional): Where the link opens: `_blank` for a new tab or `_self`. Without it, `_blank`. One of: `_blank`, `_self`.
- `design.body[].src` (string, optional): The address of the picture of an `Img`: a full address, or one variable as the whole value.
- `design.body[].alt` (string, optional): What the picture of an `Img` shows, in words, for someone who cannot see it.
- `design.body[].width` (string | number, optional): The width of an `Img` or a `Column`: a number of pixels, or a length such as `50%`.
- `design.body[].height` (string | number, optional): The height of an `Img`: a number of pixels, or a length.
- `design.body[].valign` (string, optional): Where the content of a `Column` sits: `top`, `middle` or `bottom`. One of: `top`, `middle`, `bottom`.
- `design.body[].as` (string, optional): The level of a `Heading`, from `h1` to `h6`. Without it, `h1`. One of: `h1`, `h2`, `h3`, `h4`, `h5`, `h6`.
- `design.body[].language` (string, optional): The language of a `CodeBlock`, such as `typescript` or `bash`. One it does not know is shown as plain text.
- `design.body[].theme` (string, optional): The colours of a `CodeBlock`: `oneDark`, `oneLight`, `dracula`, `nord`, `vscDarkPlus`, `vs`, `ghcolors` or `materialLight`. Without it, `oneDark`.
- `design.body[].lineNumbers` (boolean, optional): Whether a `CodeBlock` numbers its lines.
- `design.body[].stack` (boolean, optional): `true` puts the columns of a `Row` under each other on a phone. Only a `Row` takes it.
- `layout` (string): How its preview is drawn in the dashboard. One of: `start`, `center`, `split`.
- `variables` (string[]): The names of the `{{NAME}}` variables in the subject, the HTML and the plain text.
- `version` (integer): How many times it was published. 0 for a template that never was.
- `publishedAt` (string | null): When it was last published, or `null`.
- `changed` (boolean): Whether it was saved after it was last published. Emails use the published version until you publish again.
- `updatedAt` (string): When it was last saved.
- `createdAt` (string): When the template was made.

## Example

TypeScript:

```ts
await opensend.templates.edit('tmpl_02', {
  operations: [
    {
      op: 'update',
      id: 'headline',
      set: {
        text: 'Your week in review',
      },
      style: {
        color: '#111111',
      },
    },
  ],
})
```

CLI:

```bash
opensend templates edit tmpl_02 \
  --operations '[{"op":"update","id":"headline","set":{"text":"Your week in review"},"style":{"color":"#111111"}}]'
```

Answer:

```json
{
  "object": "template",
  "id": "tmpl_02",
  "name": "Weekly digest",
  "alias": "weekly-digest",
  "status": "draft",
  "subject": "Your week at a glance",
  "html": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html dir=\"ltr\" lang=\"en\"><head><meta content=\"text/html; charset=UTF-8\" http-equiv=\"Content-Type\"/><meta name=\"x-apple-disable-message-reformatting\"/></head><body><h1 style=\"color:#111111\">Your week in review</h1><p style=\"font-size:14px;line-height:24px;margin-top:16px;margin-bottom:16px\">{{SUMMARY}}</p></body></html>",
  "text": "Your week in review\n\n{{SUMMARY}}",
  "from": "",
  "replyTo": "",
  "defaults": {},
  "design": {
    "body": [
      {
        "kind": "Heading",
        "id": "headline",
        "style": {
          "color": "#111111"
        },
        "text": "Your week in review"
      },
      {
        "kind": "Text",
        "id": "summary",
        "text": "{{SUMMARY}}"
      }
    ]
  },
  "layout": "split",
  "variables": [
    "SUMMARY"
  ],
  "version": 0,
  "publishedAt": null,
  "changed": false,
  "updatedAt": "2026-11-27T09:30:00.000Z",
  "createdAt": "2026-11-05T09:30:00.000Z"
}
```
