# Unsubscribe, buyer links and your alert pages

Source: https://help.ruuster.com/idx/alerts-unsubscribe

> How buyers unsubscribe from one search or from every alert, what the link token is, and how to build your manage-alerts and unsubscribe pages on your own site in six steps.

Every alert lets the buyer stop it in two ways: the one-click unsubscribe their mail app offers, and
the links in the email to your own pages.

## The one-click unsubscribe

Each delivery object carries `List-Unsubscribe` and `List-Unsubscribe-Post` headers. Copy them onto
the email. When the buyer presses the mail app's Unsubscribe button, the app posts to our address
and the buyer is unsubscribed at once, even when your site is down. You need to build nothing for
it. A single search's alert stops that search; a digest stops every alert for the buyer.

## The link token

Every link in an alert ends in `?token=…`. The token says which buyer the link is for, and for a
single search's alert, which search. It never contains the buyer's email. It doesn't expire unless
you set `tokenTtlDays` in your settings. Your pages read it from the address and ask us who it is:

```js
// On your server, never in the browser
const res = await fetch(`https://idx.ruuster.com/v1/links/${token}`, {
  headers: { Authorization: `Bearer ${process.env.IDX_SECRET_KEY}` },
});
if (res.status === 410) {
  // The link is no longer valid: ask the visitor to sign up again
}
const { data } = await res.json();
// data = { buyer, search, searches }
```

## Build your alert pages in six steps

1. **Set your page addresses** in your alert settings: `manageUrl`, `unsubscribeUrl` and
   `searchUrl` (and `listingUrl` with `{listingId}`).
2. **Read the token** on each page from the `token` query parameter and call
   `GET /v1/links/{token}` from your server to learn the buyer and search.
3. **Show the buyer's searches** from `data.searches` (or `GET /v1/saved-searches?buyer=`), each with
   its name, frequency and status.
4. **Save changes** with `PATCH /v1/saved-searches/{searchId}` (frequency, `status: "paused"` or
   `"active"`), `DELETE /v1/saved-searches/{searchId}`, and
   `POST /v1/buyers/{buyerId}/unsubscribe` for "stop all alerts".
5. **Keep the one-click headers** on every email; they work whatever your pages do.
6. **Try it**: save a search with your own email, wait for the welcome alert, and use each link.

## Turning alerts back on

A buyer who unsubscribed can come back only with fresh consent:

```js
await fetch(`https://idx.ruuster.com/v1/buyers/${buyerId}/resubscribe`, {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.IDX_SECRET_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ consent: { text: "Yes, email me listing alerts again.", source: "https://www.example-homes.com/alerts" } }),
});
```

Their searches turn back on. An email that bounced or reported an alert as spam stays off; contact
support if that buyer asks to come back.

## Suppression

An email is kept off every later alert when the buyer unsubscribes, when it bounces, or when it
reports an alert as spam (from the events you pass back). Matches for that buyer are dropped rather
than delivered.
