# Live Events (SSE)

> Stream collection changes to browsers with Server-Sent Events. Available on Pro and Business.

- **Category:** REST API
- **Canonical Guide:** https://pottr.tangble.com/docs/realtime-events

---

>
Stream collection changes to browsers with Server-Sent Events. Available on Pro and Business.

## Connect to the Stream

GET
/events
Public Key, Pro or Business

Browsers cannot set headers on `EventSource`, so this is the one route that accepts the public key and user token in the query string. Secret keys are never accepted in a URL.

**File: `events.js`**

```javascript
const url = new URL('https://example.com/wp-json/pottr/v1/events');
url.searchParams.set('api_key', PUBLIC_KEY);
url.searchParams.set('user_token', userAccessToken);
url.searchParams.set('app', 'task-manager');
url.searchParams.set('collection', 'tasks'); // optional

const source = new EventSource(url);
source.addEventListener('entry.updated', (e) => {
  const change = JSON.parse(e.data);
  // refetch change.id from /collections/tasks/{id}
});
```

## Event Format

**File: `Stream`**

```text
id: 1042
event: entry.updated
data: {"collection":"tasks","id":87,"user_id":8,"updated_at_ts":1727170001000}
```

Events tell you what changed, not the full entry. Fetch the entry when you need its fields.

## Who Sees What

<ul>
<li>With a user token, a client receives events for entries that user owns plus public entries.</li>
<li>With only a public key, a client receives events for public entries only.</li>
<li>A secret key (server side, header only) receives all events for the app.</li>
</ul>

## Reconnecting

Pottr sends a `:keepalive` comment every 15 seconds. When the connection drops, `EventSource` reconnects with `Last-Event-ID` and Pottr replays what you missed. Events are buffered for 2 hours.

<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="16" x2="12" y2="12"></line><line x1="12" y1="8" x2="12.01" y2="8"></line></svg>
Plan and hosting

Live events need a Pro or Business license. Each open stream holds a PHP worker, so size your hosting accordingly for many concurrent viewers.
