# stensul-apply-email-variation

> Applies a styling variation to the whole email, one module, or several modules in one call. Content is untouched and the change is reversible.

Source: https://stensul.com/developers/reference/stensul-apply-email-variation/ · From the live server's tool list, 2026-09-28

- Scope: `emails:write`
- Access: write

The library's variations mode decides the shape. Mode `all`: one variation for the whole email, no `module_id`. Mode `individual`: per module, or `assignments` for several at once. The tool refuses what the mode can't express.

## Inputs

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `emailId` | string (24-char hex id) | yes | Email ID. |
| `variation` | string | no | Variation id, key or name. Required unless `assignments` is used. |
| `module_id` | integer | no | Module instance id. Required in mode `individual`; forbidden in mode `all`. |
| `assignments` | array | no | `[{ module_id, variation }]` for several modules in one write (mode `individual` only). |
| `save_version` | integer | no | Version the change is based on. |

## Example request

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "stensul-apply-email-variation",
    "arguments": {
      "emailId": "64f0c0ffee0000000000abcd",
      "variation": "Dark"
    }
  }
}
```

## Response

The restyled email with an embedded preview, or a refusal with the options the mode allows.

## Errors

| Status | Message | Cause | Fix |
| --- | --- | --- | --- |
| 401 | Authentication expired or missing | The session's authorization expired. | Sign in again when the host prompts. On a 401 or 403, the server's instructions tell the model to re-check sign-in first. |
| 403 | Insufficient OAuth scope (403): The token lacks the required scope | The API connection doesn't have the scope this tool needs. | An admin adds the scope to the API connection. Then sign in again: adding a scope revokes existing tokens. |
| 403 | API error (403): Action is unauthorized. | The signed-in user's role lacks the permission, for example `edit_campaign`. | Grant the permission to the user's role in Admin > Users & Roles. It works for other users on the same connection. |
| 409 | Version conflict | The email changed since your last read, and you passed its old `save_version`. | Read the email again and re-apply your change on the current version. Never retry by dropping `save_version`. |
