# Template API - Update

Use this endpoint to update an existing template. You can update the name, status, language, group assignment, and HTML content.

---

## Endpoint

```
PATCH https://e1.envoke.com/v2/templates/{ID}
```

Replace `{ID}` with the Envoke template ID you want to update. Authentication is via HTTP Basic Auth using your API ID and API Key. The request body must be JSON.

---

## Request Body

At least one field must be provided.

| Field | Type | Description |
|---|---|---|
| `name` | string | New name. Minimum 3 characters. |
| `status` | string | `published` or `unpublished`. |
| `language` | string or integer | Language code (e.g. `en`, `fr`) or numeric language ID. |
| `group` | string or integer | Group name or group ID to assign. Pass an empty string (`""`) to remove the group assignment. |
| `html` | string | Replacement HTML content. Maximum 200 KB. |

The fields `external_id`, `preview_url`, `create_time`, and `modified_time` are silently ignored if included in the request body. If `id` is included, it must match the `{ID}` in the URL — if they differ, a validation error is returned: `"Provided 'id': {url_id} does not match 'id' in request body ({body_id})"`.

---

## Response

On success, the API returns the updated template object:

```json
{
  "success": true,
  "result_text": "Updated",
  "result_data": {
    "id": "42",
    "external_id": "a1b2c3d4e5f6",
    "preview_url": "https://engage.envoke.com/m/acme-corp/m/a1b2c3d4e5f6",
    "name": "Updated Welcome Email",
    "status": "published",
    "language": "en",
    "group": "",
    "create_time": "2026-04-11 09:00:00",
    "modified_time": "2026-04-11 15:00:00"
  }
}
```

`html` is not included in the update response body. To retrieve the updated HTML, use `GET /v2/templates/{id}?include_html=1`.

---

## Validation Errors

All errors, including not-found, use the validation error envelope:

```json
{
  "success": false,
  "result_text": "Validation failed, see 'result_data' -> 'errors'",
  "result_data": {
    "errors": [
      "The field 'name' must be at least 3 characters long"
    ]
  }
}
```

Common errors:

| Error | Cause |
|---|---|
| `Request body may not be empty` | No JSON body was provided. |
| `The field 'name' must be at least 3 characters long` | New `name` was fewer than 3 characters. |
| `The field 'html' may not be longer than 200kB` | HTML content exceeded the 200 KB limit. |
| `Invalid 'status'` | `status` was not `published` or `unpublished`. |
| `Invalid 'language'` | The `language` value was not recognised. |
| `Invalid 'group'` | The group was not found or is not of type `message_template`. |
| `Item with id '{id}' not found` | The `{ID}` in the URL does not match any template in your account. |

---

## Examples

### Rename a template

```bash
curl -X PATCH -gs \
  -u "$API_ID:$API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Updated Welcome Email"}' \
  "https://e1.envoke.com/v2/templates/42"
```

### Unpublish a template

```bash
curl -X PATCH -gs \
  -u "$API_ID:$API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"status": "unpublished"}' \
  "https://e1.envoke.com/v2/templates/42"
```

### Assign to a group

```bash
curl -X PATCH -gs \
  -u "$API_ID:$API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"group": "Seasonal Campaigns"}' \
  "https://e1.envoke.com/v2/templates/42"
```

### Remove group assignment

```bash
curl -X PATCH -gs \
  -u "$API_ID:$API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"group": ""}' \
  "https://e1.envoke.com/v2/templates/42"
```

### Replace HTML content

```bash
curl -X PATCH -gs \
  -u "$API_ID:$API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html": "<html><body><h1>New content</h1></body></html>"}' \
  "https://e1.envoke.com/v2/templates/42"
```

### Update multiple fields at once

```bash
curl -X PATCH -gs \
  -u "$API_ID:$API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Bienvenue", "language": "fr", "group": "Onboarding"}' \
  "https://e1.envoke.com/v2/templates/42"
```

---

*Note: The curl examples above are formatted for readability. All requests must use properly encoded URLs.*

*Full reference, OpenAPI description, and Postman collection: [developers.envoke.com](https://developers.envoke.com).*
