# Update template

> PATCH /templates/:id — edit a template's name, subject, or body.

`PATCH /templates/:id`

Updates only the fields you provide; omitted fields are left unchanged.

**Body parameters**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | No | New name. |
| `alias` | string | null | No | New alias. Pass `null` to clear. Must be unique across your templates. |
| `subject` | string | null | No | New default subject. Pass `null` to clear. |
| `html` | string | null | No | New HTML body. Pass `null` to clear. |
| `text` | string | null | No | New plain-text body. Pass `null` to clear. |
| `from` | string | null | No | New default sender address. Use `"Your Name <sender@domain.com>"` for a friendly name. Pass `null` to clear. |
| `reply_to` | string | string[] | null | No | New default Reply-To address, or an array of addresses (an array is stored and returned as a single comma-separated string). Pass `null` to clear. |
| `variables` | array | No | Replaces the template's variables (up to 50). Each is an object with `key`, `type`, and optional `fallback_value` — same shape as on create. |

**variables[] object**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `key` | string | Yes | The variable key. Reserved names that cannot be used: `FIRST_NAME`, `LAST_NAME`, `EMAIL`, `UNSUBSCRIBE_URL`, `contact`, `this`. Keys must start with a letter or underscore and contain only letters, digits, underscores, or dots. |
| `type` | 'string' | 'number' | No | The type of the variable. Defaults to `string` when omitted. |
| `fallback_value` | string | number | null | No | The value used when none is supplied at send time. Must match `type`. |

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.templates.update('43f68331-0622-4e15-8202-246a0388854b', { "subject": "Welcome aboard, {{first_name}}!" });
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Templates.update("43f68331-0622-4e15-8202-246a0388854b", {
  "subject": "Welcome aboard, {{first_name}}!"
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->templates->update('43f68331-0622-4e15-8202-246a0388854b', [
  'subject' => "Welcome aboard, {{first_name}}!"
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Templates.update("43f68331-0622-4e15-8202-246a0388854b", {
  "subject": "Welcome aboard, {{first_name}}!"
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

updated, err := client.Templates.Update("43f68331-0622-4e15-8202-246a0388854b", &sendping.UpdateTemplateRequest{
    Subject: sendping.Set("Welcome aboard, {{first_name}}!"),
})
```

**Rust**

```rust
use sendping::{SendPing, UpdateTemplateOptions};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = UpdateTemplateOptions::new().with_subject("Welcome aboard, {{first_name}}!");
let _updated = mb.templates.update("43f68331-0622-4e15-8202-246a0388854b", params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.UpdateTemplateRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

UpdateTemplateRequest request = UpdateTemplateRequest.builder()
        .subject("Welcome aboard, {{first_name}}!")
        .build();

SendPingResponse response = sendping.templates().update(
        "43f68331-0622-4e15-8202-246a0388854b",
        request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.TemplateUpdateAsync("43f68331-0622-4e15-8202-246a0388854b", new TemplateUpdateOptions
{
    Subject = "Welcome aboard, {{first_name}}!",
});
```

**cURL**

```bash
curl -X PATCH 'https://www.sendping.co/api/templates/43f68331-0622-4e15-8202-246a0388854b' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{ "subject": "Welcome aboard, {{first_name}}!" }'
```

**CLI**

```bash
sendping templates update 43f68331-0622-4e15-8202-246a0388854b \
  --subject 'Welcome aboard, {{first_name}}!'
```

Also edits a draft (does not auto-publish). Returns `{ object: "template", id }`. A published template keeps serving its last published snapshot until you [publish](https://www.sendping.co/docs/api/templates-publish) again.

### Field limits

These caps are enforced at the API boundary. Exceeding one returns a `validation_error` naming the field, e.g. *`subject` must be 998 characters or fewer.*

| Field | Maximum length |
| --- | --- |
| `name` | 255 |
| `subject` | 998 |
| `from` | 320 |
| `reply_to` | 320 |
| `alias` | 255 |

> **Note:** Errors: `not_found` if no template with that id (or alias) belongs to you; `validation_error` if a field exceeds its maximum length, if the new `alias` is already used by another of your templates, or if `variables` is invalid (not an array, more than 50 entries, reserved/duplicate/invalid key, unknown `type`, or a `fallback_value` that does not match its `type`). See [Errors](https://www.sendping.co/docs/api/errors).
