Skip to main content

Introduction

Subscribe to product-related notifications and updates.

More information about the module's user interface https://doc.oneentry.cloud/docs/category/events


🎯 What does this module do?

The Events module lets you subscribe users to product notifications - like an email when a product is back in stock, or an alert when the price drops. You configure the events in the OneEntry admin panel; the SDK manages who is subscribed to what.

Think of it as a product subscription system - users subscribe to specific products (or forms) and receive notifications when something changes.

🚀 Quickstart

Initialize the module from defineOneEntry:


const { Events } = defineOneEntry(
"your-project-url", {
"token": "your-app-token"
}
);

List the available events (public — no authorization needed):

// Fetch all events configured in the admin panel.
const events = await Events.getAllEvents();

events.forEach((event) => {
console.log(event);
});

To subscribe a user to a product event you must be authorized first, then call subscribeByMarker(marker, productId, langCode?):

// Requires an authorized user (see AuthProvider).
const ok = await Events.subscribeByMarker("product_price_change", 12345, "en_US");
console.log(ok); // true on success

✨ Key Concepts

What is a Product Event?

A product event is a notification triggered by changes to a product:

  • Trigger - what happens to the product (e.g. "back in stock", "price drop")
  • Notification - what subscribers receive (email or push)
  • Subscribers - users who opted in for this product's updates
  • Template - the notification message content (configured in the admin panel)

The module also supports form events: subscribe to / unsubscribe from notifications tied to a form submission with subscribeToForm / unsubscribeFromForm.

Notification channels

ChannelDescriptionBest For
EmailSend email messagesRestock alerts, price drops, newsletters
Push NotificationMobile/browser alertsUrgent alerts, flash sales

📋 What You Need to Know

Events are configured in the admin panel

Triggers, channels, and templates are set up in the OneEntry admin panel. The SDK does not create events or fire them manually — events fire automatically when product data changes. The SDK is for listing events and managing subscriptions.

Authorization

getAllEvents() is public. Every subscription method (getAllSubscriptions, subscribeByMarker, unsubscribeByMarker, subscribeToForm, unsubscribeFromForm, getFormSubscriptions) requires an authorized user — see AuthProvider.

Template variables

Use placeholders in notification templates to include product details like name, price, and availability. Templates are edited in the admin panel.


📊 Quick Reference Table - Common Methods

MethodWhat It Does
getAllEvents()Get all available events
getAllSubscriptions() 🔐Get all product subscriptions
subscribeByMarker() 🔐Subscribe to a product event by marker
unsubscribeByMarker() 🔐Unsubscribe from a product event by marker
subscribeToForm() 🔐Subscribe to a form event by marker
unsubscribeFromForm() 🔐Unsubscribe from a form event by marker
getFormSubscriptions() 🔐Get all form subscriptions

🔐 methods require user authorization — see AuthProvider. getAllEvents() is public.


❓ Common Questions (FAQ)

How do I create or edit product events?

Events are created and configured in the OneEntry admin panel (Events section) — set up triggers, channels, and templates there, then activate the event. The SDK only lists events and manages subscriptions.


Can I manually trigger a product event from my code?

No. The SDK doesn't support manual triggers — events fire automatically based on the triggers configured in OneEntry when product data changes.


Why does subscribing fail with an authorization error?

Subscription methods require an authorized user. Authorize first via the AuthProvider module, then call subscribeByMarker / subscribeToForm. getAllEvents() works without authorization.


🎓 Best Practices

  • Authorize the user before calling any subscription method.
  • Use descriptive event markers (e.g. product_back_in_stock, product_price_drop).
  • Always offer an easy unsubscribe path (unsubscribeByMarker / unsubscribeFromForm).
  • Handle subscription errors gracefully and check the IError return shape.