subscribe(email: string): Promise<TResponseStatus | undefined>¶
The subscribe
method allows you to subscribe to a newsletter via api.
Input parameters¶
email¶
email
is a mandatory parameter of string
type which represents an email that we are trying to sign up for a newsletter.
Returned value¶
A returned value is has a type of Promise<TResponseStatus | undefined>
. You can learn more about TResponseStatus here.
Event Bus events¶
This API method dispatches the following events with the Event Bus:
- FlashMessengerApi.addFlashMessage - when handling messages that come from a server
- FlashMessengerApi.addFlashMessages - when handling messages that come from a server
Example¶
In this example we make a NewsletterFormApi
call to subscribe to a newsletter.
useStorefront(async (storefront) => {
const newsletterFormApi = storefront.getApiSync('NewsletterFormApi');
await newsletterFormApi.subscribe('email@example.com');
});