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

# Get Preferences Token

> Generate a signed token to embed the subscription preferences widget

Generate a signed token that allows you to embed the subscription preferences widget on your website. This widget lets users manage their email subscription preferences directly from your application.

<Warning>
  **Security:** Call this endpoint from your backend only. Never expose your API
  key to the frontend. The token is valid for 1 hour.
</Warning>

## Request Body

<ParamField body="email" type="string" required>
  The subscriber's email address. Must be a valid email of an existing
  subscriber.
</ParamField>

## Example

<CodeGroup>
  ```typescript Node.js SDK theme={null}
  import Sequenzy from "sequenzy";

  const client = new Sequenzy("YOUR_API_KEY");

  const { data, error } = await client.widgets.preferences.generateToken({
    email: "user@example.com",
  });

  if (data) {
    // Use the token in your frontend iframe
    const widgetUrl = `https://sequenzy.com/embed/preferences?token=${data.token}`;
  }
  ```

  ```bash cURL theme={null}
  curl -X POST "https://api.sequenzy.com/api/v1/widgets/preferences/token" \
    -H "X-API-Key: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"email": "user@example.com"}'
  ```
</CodeGroup>

## Using the Token

Once you have the token, embed the widget in your frontend:

```html theme={null}
<iframe
  src="https://sequenzy.com/embed/preferences?token={TOKEN}"
  width="100%"
  height="400"
  frameborder="0"
  style="border: none; max-width: 500px;"
></iframe>

<script>
  // Auto-resize iframe based on content
  window.addEventListener("message", function (e) {
    if (e.data.type === "sequenzy-preferences-resize") {
      var iframe = document.querySelector('iframe[src*="/embed/preferences"]');
      if (iframe) iframe.style.height = e.data.height + "px";
    }
  });
</script>
```

## Responses

<ResponseExample>
  ```json 200 theme={null}
  {
    "success": true,
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }
  ```

  ```json 400 Invalid email theme={null}
  {
    "success": false,
    "error": {
      "code": "VALIDATION_ERROR",
      "message": "Invalid email format"
    }
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "success": false,
    "error": {
      "code": "UNAUTHORIZED",
      "message": "Invalid API key"
    }
  }
  ```

  ```json 404 Not found theme={null}
  {
    "success": false,
    "error": {
      "code": "NOT_FOUND",
      "message": "Subscriber not found"
    }
  }
  ```

  ```json 500 Server error theme={null}
  {
    "success": false,
    "error": {
      "code": "SERVER_ERROR",
      "message": "Server configuration error"
    }
  }
  ```
</ResponseExample>

<Note>
  The subscriber must already exist in Sequenzy. If the subscriber doesn't
  exist, create them first using the [Create
  Subscriber](/api-reference/subscribers/create) endpoint.
</Note>
