# Email unsubscribe

> Stop one kind of email from the link in the message.

URL: https://renzo-digital.com/docs/resources/email

Every Renzo email carries an unsubscribe link and a `List-Unsubscribe` header. These two calls act on that link. The signed token in the link is the only key, so no token or sign-in is needed. Anyone who holds the link may call them.

## Endpoints

| Operation | What it does | Auth |
| --- | --- | --- |
| `POST /api/v1/email/unsubscribe` | Stop the kind of email named by the link: `{"token": "..."}`. | None, the link token is the key |
| `POST /api/v1/email/one-click-unsubscribe` | The one-click target that mail providers post to. Takes `?token=`. | None, the link token is the key |

## Example: unsubscribe from a summary

```bash tab="curl"
curl -X POST "$BASE/api/v1/email/unsubscribe" \
  -H "Content-Type: application/json" \
  -d '{"token": "eyJhbGciOi...example"}'
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]

answer = requests.post(
    f"{BASE}/api/v1/email/unsubscribe",
    json={"token": "eyJhbGciOi...example"},
)
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE } = process.env;

const answer = await fetch(`${BASE}/api/v1/email/unsubscribe`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ token: "eyJhbGciOi...example" }),
});
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

The answer is `200`:

```json title="Response"
{
  "kind": "digest",
  "type_key": "market.pre_market_summary",
  "type_label": "Pre-market summary",
  "alert_id": null,
  "ticker": null
}
```

## Rules and edge cases

- **Kinds.** `kind` is `digest` for a summary email, or `price_alert` for an alert email.
- **Digest.** For `digest`, the answer names the type that was turned off in `type_key` and `type_label`. Email is switched off for that type only.
- **Price alert.** For `price_alert`, the answer holds `alert_id` and `ticker`. Email is taken off that one alert, and its other channels keep firing. An alert that had only email is paused, so resuming it brings email back. See [Price alerts](https://renzo-digital.com/docs/resources/price-alerts).
- **Gone targets.** `type_key`, `type_label`, `alert_id` and `ticker` are `null` when the type or the alert no longer exists.
- **Twice.** Calling again answers the same.
- **One-click.** `POST /api/v1/email/one-click-unsubscribe` is the RFC 8058 target. Mailbox providers post to it. The `token` query parameter (1 to 256 characters) is the only key. The form body is ignored. It answers `200` with `{"unsubscribed": true}`.
- **Bad link.** A damaged token, or one Renzo did not issue, answers `400` [`notification_unsubscribe_token_invalid`](https://renzo-digital.com/docs/error-codes#notification_unsubscribe_token_invalid).
- **Turn it back on.** A signed-in customer can switch email on again in preferences. See [Notifications](https://renzo-digital.com/docs/resources/notifications).

## Errors

| Code | Status | When |
| --- | --- | --- |
| [`notification_unsubscribe_token_invalid`](https://renzo-digital.com/docs/error-codes#notification_unsubscribe_token_invalid) | 400 | The unsubscribe link is damaged or was not issued by Renzo. |

Request errors, such as [`validation_failed`](https://renzo-digital.com/docs/error-codes#validation_failed), can come from any call. See [Errors](https://renzo-digital.com/docs/concepts/errors).

## Reference

- [Email in the API reference](https://renzo-digital.com/docs/api#tag/email)
