Events
Subscribe to product-related notifications and updates.
More information about the module's user interface https://doc.oneentry.cloud/docs/category/events (opens in a new tab)
The Events module subscribes users to product notifications, such as an email when a product is back in stock or an alert when its price drops. Users subscribe to specific products (or forms) and get notified when something changes. You configure the events in the OneEntry admin panel; the SDK manages who is subscribed to what.
Quickstart
Initialize the module from defineOneEntry:
const { } = defineOneEntry( , { });
List the available events (requires an authenticated user):
// Fetch all events configured in the admin panel.
const events = await Events.getAllEvents();
if (Array.isArray(events)) {
events.forEach((event) => console.log(event.identifier));
} else {
console.error(events.message); // IError, e.g. 401 without authorization
}
To subscribe a user to a product event, authorize the user first, then call subscribeByMarker(marker, productId, langCode?):
// Requires an authenticated user (see AuthProvider).
const ok = await Events.subscribeByMarker("product_price_change", 12345, "en_US");
console.log(ok); // true on success
Product events
A product event is a notification triggered by a change to a product. It consists of:
- a trigger: what happens to the product (e.g. "back in stock", "price drop");
- a notification: what subscribers receive (email or push);
- subscribers: users who opted in to updates for this product;
- a template: the content of the notification message, configured in the admin panel. Templates can include placeholders for product details such as name, price and availability.
The module also supports form events. Use subscribeToForm / unsubscribeFromForm to subscribe to or unsubscribe from notifications tied to a form submission.
Notification channels
| Channel | Description | Best For |
|---|---|---|
| Send email messages | Restock alerts, price drops, newsletters | |
| Push Notification | Mobile/browser alerts | Urgent alerts, flash sales |
| WebSocket | Real-time messages to connected clients | In-app notifications (WebSocket) |
Configuring events
Triggers, channels and templates are set up in the Events section of the OneEntry admin panel, where you also activate the event. The SDK can't create events or trigger them manually: events fire automatically, based on the configured triggers, when product data changes. The SDK only lists events and manages subscriptions.
Authorization
Every method, including getAllEvents() and the subscription methods (getAllSubscriptions, subscribeByMarker, unsubscribeByMarker, subscribeToForm, unsubscribeFromForm, getFormSubscriptions), requires an authenticated user, so a call without authorization fails with an authorization error. Authorize the user first with AuthProvider. Handle subscription errors by checking for the IError return shape.
Methods
| Method | What 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 |
🔐 Requires user authorization; see AuthProvider.
Related
- AuthProvider: authorize users before managing subscriptions
- Products: products that trigger events
- Forms: forms whose submissions can be subscribed to
- Users: users who subscribe to notifications