> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pocketflows.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Respect customer consent

> Keep opted-out customers from being messaged, and find out when a customer unsubscribes

Your system may already know that a customer doesn't want marketing, and customers can also opt out
through Pocketflows, from an email's unsubscribe link or by replying STOP to a text. This guide covers
both directions: telling Pocketflows about an opt-out, and finding out about one.

## Tell Pocketflows a customer opted out

### Of everything

To stop every campaign and trigger from reaching a customer, now and in the future, unsubscribe them
with the `future` type:

```
POST /customers/:id/unsubscribe

Body
{
  "type": "future"
}
```

Any campaign or trigger the customer is part of stops for them straight away. Afterwards the
customer's `unsubscribed` value is `future`.

> [!NOTE]
>
> The `all` type is narrower than its name suggests: it unsubscribes the customer only from the
> campaigns and triggers they are part of right now, and new campaigns and triggers can still reach
> them. To opt a customer out of everything, use `future`.

### Of one campaign or trigger

```
POST /customers/:id/unsubscribe

Body
{
  "type": "trigger",
  "trigger_id": "tr_..."
}
```

Use `"type": "campaign"` with a `campaign_id` for a campaign.

## Undo an opt-out

Resubscribe the customer with `POST /customers/:id/resubscribe`. It accepts the `future`,
`campaign` and `trigger` types:

```
POST /customers/:id/resubscribe

Body
{
  "type": "future"
}
```

* **To undo `future`,** resubscribe with `future`. This doesn't undo unsubscribes from individual
  campaigns or triggers.
* **To undo a single campaign or trigger,** resubscribe with `campaign` and a `campaign_id`, or
  `trigger` and a `trigger_id`. While the customer is unsubscribed with `future`, this returns `422`:
  resubscribe them with `future` first.
* **To undo `all`,** there is no `all` type to resubscribe with. An `all` unsubscribe is recorded as
  one unsubscribe for each campaign and trigger the customer was part of, so call
  `GET /customers/:id/unsubscribe_info` and resubscribe the customer to each campaign in
  `unsubscribed_campaigns` and each trigger in `unsubscribed_triggers`.

## How customers opt out through Pocketflows

* **Email.** By default, emails from campaigns and triggers include an unsubscribe link, and supported
  senders also add a one-click unsubscribe header for mail apps. Either way, the customer is
  unsubscribed with the `future` type.
* **SMS.** When a customer replies STOP, Pocketflows adds them to the unsubscribe list of the phone
  number they replied to, and texts from that number skip them. Replying START removes them again.
  STOP doesn't change the customer's `unsubscribed` value.

Syncing a customer doesn't undo either kind of opt-out.

## Find out when a customer unsubscribes

Subscribe to the `customer.unsubscribe` [webhook event](https://docs.pocketflows.com/reference/webhooks.md).
It's sent when a customer unsubscribes through an email link, through an
[unsubscribe embed](#build-your-own-unsubscribe-page), or through the API. It is not sent when a
customer replies STOP to a text.

To check a single customer, call `GET /customers/:id/unsubscribe_info`. `unsubscribed_from_all` is
`true` when the customer is unsubscribed with `future`, and `unsubscribed_campaigns` and
`unsubscribed_triggers` list any individual unsubscribes.

## Build your own unsubscribe page

To let customers opt out inside your product, create an unsubscribe embed for the customer and show
its URL:

```
POST /customers/:id/unsubscribe_embeds
```

The response includes a `url` for a hosted page with an "Unsubscribe from all" button, which you can
link to or show in an iframe. Submitting it unsubscribes the customer with the `future` type.

## Related

* [Sending semantics](https://docs.pocketflows.com/reference/sending-semantics.md) for every check Pocketflows runs before it sends.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.