const sub = await events.subscribe({
events: ["order.created", "payment.completed"],
name: "checkout-listener",
});
await events.unsubscribe(sub.subscription_id);Creates a subscription so your app can receive the named events through the SDK. Delivery behavior comes from the profile configured for the Event App in the portal.
Listen#
Node / long-lived process:
const handle = events.listen(
{ events: ["order.created"] },
(message) => {
if ("type" in message && message.type === "connected") {
console.log("connected", message.listener_id);
return;
}
console.log(message.type, message.payload);
}
);
handle.close();listen() auto-reconnects after disconnects/server restarts (exponential backoff, default 1s → 30s). Pass reconnect: false to disable, or tune with reconnectDelayMs / reconnectMaxDelayMs. Call handle.close() to stop reconnecting.
In the browser, use the listen URL from the SDK:
const url = events.listenUrl({ events: ["order.created"] });
const es = new EventSource(url);Delivered event envelope:
{
"id": "<event_id>",
"type": "order.created",
"created_at": "…",
"event_app_id": "evt_app_…",
"delivery_profile": "reliable",
"payload": {},
"metadata": {}
}Use listen() for live SDK consumers. Choose a delivery profile in the portal when you need stronger durability guarantees.