Skip to content

subscribe(productVariantId: number, email?: string): Promise<boolean>

The subscribe is an asynchronous method that allows to subscribe for notifications about availability of a product with a given id.

Input parameters

productVariantId

productVariantId is a mandatory parameter of the string type that represents the id of a product for which we want to enable the availability notifications for.

email

email is an optional field of the string type which represents an email of a user who will be subscribed to these notifications.

Returned value

A returned value has a type of Promise<boolean> indicating whether the user was successfully subscribed or not.

Event Bus events

This API method dispatches the following events with the Event Bus:

Example

In this example we make a AvailabilityNotifierApi call to disable notifications about availability of a product with a given id.

useStorefront(async (storefront) => {
    const availabilityNotifierApi = await storefront.getApi('AvailabilityNotifierApi');

    await availabilityNotifierApi.subscribe(12);
});

Availability Notifier API methods reference