# 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. 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 { MailBlastr } from 'mailblastr';

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.templates.update('tmpl_8f5c2a1e', { "subject": "Welcome aboard, {{first_name}}!" });
console.log({ data, error });
```

**Ruby**

```ruby
require "mailblastr"

Mailblastr.api_key = "mb_xxxxxxxxx"

Mailblastr::Templates.update("tmpl_8f5c2a1e", {
  "subject": "Welcome aboard, {{first_name}}!"
})
```

**PHP**

```php
$mailblastr = Mailblastr::client('mb_xxxxxxxxx');

$mailblastr->templates->update('tmpl_8f5c2a1e', [
  'subject' => "Welcome aboard, {{first_name}}!"
]);
```

**Python**

```python
import mailblastr

mailblastr.api_key = "mb_xxxxxxxxx"

mailblastr.Templates.update("tmpl_8f5c2a1e", {
  "subject": "Welcome aboard, {{first_name}}!"
})
```

**Go**

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    req, _ := http.NewRequest("PATCH", "https://api.mailblastr.com/templates/tmpl_8f5c2a1e", strings.NewReader(`{ "subject": "Welcome aboard, {{first_name}}!" }`))
    req.Header.Set("Authorization", "Bearer mb_xxxxxxxxx")
    req.Header.Set("Content-Type", "application/json")
    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    out, _ := io.ReadAll(res.Body)
    fmt.Println(string(out))
}
```

**Rust**

```rust
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let res = Client::new()
        .patch("https://api.mailblastr.com/templates/tmpl_8f5c2a1e")
        .header("Authorization", "Bearer mb_xxxxxxxxx")
        .header("Content-Type", "application/json")
        .body(r#"{ "subject": "Welcome aboard, {{first_name}}!" }"#)
        .send()
        .await?;
    println!("{}", res.text().await?);
    Ok(())
}
```

**Java**

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.mailblastr.com/templates/tmpl_8f5c2a1e"))
    .header("Authorization", "Bearer mb_xxxxxxxxx")
    .header("Content-Type", "application/json")
    .method("PATCH", HttpRequest.BodyPublishers.ofString("""
{ "subject": "Welcome aboard, {{first_name}}!" }
"""))
    .build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

**.NET**

```csharp
using System.Net.Http;
using System.Text;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Patch, "https://api.mailblastr.com/templates/tmpl_8f5c2a1e");
request.Headers.Add("Authorization", "Bearer mb_xxxxxxxxx");
request.Content = new StringContent(@"{ ""subject"": ""Welcome aboard, {{first_name}}!"" }", Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

**cURL**

```bash
curl -X PATCH 'https://api.mailblastr.com/templates/tmpl_8f5c2a1e' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{ "subject": "Welcome aboard, {{first_name}}!" }'
```

**CLI**

```bash
mailblastr templates update tmpl_8f5c2a1e \
  --subject 'Welcome aboard, {{first_name}}!'
```

Also edits a draft (does not auto-publish). Returns `{ object: "template", id }`.
