REST API
Live Events (SSE)
Stream collection changes to browsers with Server-Sent Events. Available on Pro and Business.
Connect to the Stream
GET/eventsPublic 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.
events.js
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
Stream
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
- With a user token, a client receives events for entries that user owns plus public entries.
- With only a public key, a client receives events for public entries only.
- A secret key (server side, header only) receives all events for the app.
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.
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.