# Set up double opt-in

> Make sign-ups from your site wait for an email confirmation. Set Wait for confirmation, send subscribe requests, trigger a workflow on Subscribe Request Submitted, put {{subscribeLink}} in the email, and check the confirmation page.

With double opt-in, a sign-up on your site does not subscribe the customer straight away. Releva records the request, a workflow sends a confirmation email, and the customer is subscribed only when they open the link in it. Because your access token is public, this is also what stops someone who copies it from subscribing other people’s addresses.

The chain has four parts:

1. The setting **Subscription Request Behavaior** is **Wait for confirmation**.
2. Your site sends a subscribe request (`Releva.requestSubscribe` or `POST /api/v0/subscribe/request`). Releva answers `202` and records a `subscribeRequest` event.
3. A triggered workflow on that event sends an email with the `{{subscribeLink}}` merge tag.
4. The customer opens the link. `GET /api/v0/subscribe/oneclick/{payload}` subscribes them with the subscriptions from the request and shows a confirmation page.

## Before you start

* **Subscription Management** is **Internal** in **Settings › Messaging**. In **External** mode `{{subscribeLink}}` renders empty, so double opt-in cannot work.
* You have your shop’s **access token** (**Settings › Shop & Integration**; see [Find your Access Token and Secret Key](https://releva.ai/documentation/guides/shop-settings/find-your-api-keys/)).
* The sign-up form collects an **email address**. The confirmation link subscribes by email address only, so a request with only a phone number cannot be confirmed through it.

## Steps

1. Open **Settings › Messaging** and stay on the **General** tab.

2. Under **Subscription Request Behavaior**, select **Wait for confirmation**, then select **Save**. Step-by-step screenshots are in [Choose how Releva manages subscriptions](https://releva.ai/documentation/guides/consent/choose-how-releva-manages-subscriptions/).

3. Open **Workflows › Triggered** and create a workflow.

4. Under **Trigger on**, select **Event**. Under **Event**, select **Subscribe Request Submitted**.

5. Under **Campaign Scope**, select a scope that reaches people who are not subscribed yet. **Opt-in Marketing** sends only to subscribed profiles, so it never reaches someone waiting to confirm. **Opt-out Marketing** reaches them unless they unsubscribed before. **Transactional** reaches them whatever their status; the admin warns never to use it for marketing messages, so agree the choice with whoever owns your privacy policy.

6. Add an **Email** step and put the `{{subscribeLink}}` merge tag in its content, for example as the target of a “Confirm your subscription” button.

7. Switch the workflow **On**.

8. Send the sign-ups from your site with `Releva.requestSubscribe(...)` or `POST /api/v0/subscribe/request`. Fields, responses and the SDK call are in [Subscribe a customer from the browser](https://releva.ai/documentation/reference/consent/subscribe-from-the-browser/).

   ```plaintext
   curl -X POST 'https://releva.ai/api/v0/subscribe/request' \
     -H "authorization: Bearer $RELEVA_ACCESS_TOKEN" \
     -H 'content-type: application/json' \
     -d '{ "email": "maria@example.com", "subscriptions": ["weeklyNewsletter"], "tags": ["footer-form"] }'
   ```

## What the confirmation link does

`{{subscribeLink}}` points to `/api/v0/subscribe/oneclick/{payload}` on your shop’s click-tracking host. Releva builds the encrypted payload when it renders the email; you never build it yourself and it needs no `authorization` header.

* The payload carries the email address and, when the email was sent by a workflow triggered by `subscribeRequest`, the subscriptions from that request.
* Opening the link subscribes the customer and **adds** those subscriptions to their list. Without subscriptions in the request, your user-visible subscriptions apply.
* The page is in English only. After 10 seconds it redirects to your shop.

| Status | Page title               | Text                                                                                   |
| ------ | ------------------------ | -------------------------------------------------------------------------------------- |
| `200`  | **Subscribe Successful** | `Email address "maria@example.com" has been successfully subscribed.`                  |
| `400`  | **Subscribe Failed**     | `The subscribe link you followed seems to be invalid.` The link was changed or broken. |
| `500`  | **Subscribe Failed**     | `We encountered an internal error and were unable to subscribe you.`                   |

## Check it worked

1. Send a test sign-up with an address you control. The request answers `202` with `{}`.
2. Open the profile under **Data Platform › Profiles**. The **Recent Events** tab lists a `subscribeRequest` event, and the profile is not subscribed yet.
3. Open the confirmation email and select the link. The **Subscribe Successful** page appears.
4. Reload the profile. It shows **Subscribed**, with the requested subscriptions.

## Troubleshooting

**The request answers `200` instead of `202`.** **Subscription Request Behavaior** is **Subscribe right away**. Change it to **Wait for confirmation** and save.

**No confirmation email arrives.** Check that the workflow is **On**, that its event is **Subscribe Request Submitted**, and that its **Campaign Scope** is not **Opt-in Marketing**.

**The email arrives but the link is empty.** **Subscription Management** is **External**. `{{subscribeLink}}` renders only in **Internal** mode.

**The customer is subscribed without the requested subscriptions.** The email that carried the link was not sent by a workflow triggered by `subscribeRequest`, so the link has no subscriptions in it. Send the confirmation from the triggered workflow.

**Server-side subscribes skip the confirmation.** `POST /api/v0/subscribe` and the **Subscribe** button on a profile always subscribe right away. Only storefront requests wait for confirmation.

## Next steps

* [Subscribe a customer from the browser](https://releva.ai/documentation/reference/consent/subscribe-from-the-browser/): See every field of the subscribe request and the SDK call.
* [How workflows work](https://releva.ai/documentation/learn/workflows/how-workflows-work/): Learn how triggered workflows, steps and the On switch behave.
* [Unsubscribe links and one-click unsubscribe](https://releva.ai/documentation/reference/consent/unsubscribe-links-and-one-click/): See how customers leave again once they are subscribed.