Skip to content

Update unsubscribeAll to POST directly to basket #18249

Description

@robhudson

Description

The unsubscribeAll function currently sends a POST request to the preference center on mozilla.org to unsubscribe users from all newsletters. However, this approach has some limitations and potential issues:

  1. The preference center itself forwards the request to Basket, making this an indirect method.
  2. The preference center recently adopted a js-only implementation for handling this request, which may cause unsubscribeAll to break or behave unpredictably in the future.

Proposed Solution

To ensure future reliability unsubscribeAll should send requests directly to Basket. This is the more direct and stable approach since Basket is the service ultimately handling the unsubscription.

The direct API call would:

  • POST to https://basket.mozilla.org/news/unsubscribe/<token>/
  • Include a request body with optout=Y, this is the signal to basket to unsubscribe from ALL newsletters and flags the user as opted out of emails.

Implementation Example

Here’s how the request could look using fetch:

await fetch(`https://basket.mozilla.org/news/unsubscribe/${userToken}/`, {
    method: "POST",
    body: "optout=Y",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        "X-Requested-With": "XMLHttpRequest",
    },
});

┆Issue is synchronized with this Jira Task

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions