Newsletter
First-party newsletter subscribe and unsubscribe
Subscribe
First-party opt-in stored in Behio (the merchant owns the emails). No authentication needed:
const { data } = await client.newsletter.subscribe({
email: '[email protected]',
locale: 'cs', // optional, preferred locale captured at signup
source: 'footer', // optional, where the opt-in came from ("footer", "checkout", ...)
});
// data: { success: true, alreadySubscribed: boolean }Subscribing is idempotent: one row per email per shop, and a previously unsubscribed email is re-activated.
Honeypot
The input accepts an optional website field as a spam honeypot. Render it as a hidden input real users never fill; when a bot fills it, the API responds with success but stores nothing. Keep it empty (or omit it) in legitimate calls.
Unsubscribe
Idempotent and never reveals whether the email existed:
await client.newsletter.unsubscribe('[email protected]');
// { success: true }Checkout Opt-in
The checkout newsletter checkbox does not call subscribe directly. Pass the customer's choice as newsletterOptIn in checkout.createOrder, and render the checkbox default from ShopInfo.checkout.newsletterOptInDefault (CHECKED / UNCHECKED / HIDDEN).
React Hooks
import { useNewsletterSubscribe } from '@behio/storefront-sdk/react';
const subscribe = useNewsletterSubscribe();
subscribe.mutate({ email, source: 'footer' });useNewsletterUnsubscribe() is the matching unsubscribe mutation.