Last Updated: 3/9/2026
API Realtime
The Realtime API is implemented via Server-Sent Events (SSE). Generally, it consists of 2 operations:
- establish SSE connection
- submit client subscriptions
SSE events are sent for create, update and delete record operations.
You could subscribe to a single record or to an entire collection.
When you subscribe to a single record, the collection’s ViewRule will be used to determine whether the subscriber has access to receive the event message.
When you subscribe to an entire collection, the collection’s ListRule will be used to determine whether the subscriber has access to receive the event message.
GET
/api/realtime
Establishes a new SSE connection and immediately sends a PB_CONNECT SSE event with the created client ID.
NB! The user/superuser authorization happens during the first Set subscriptions call.
If the connected client doesn’t receive any new messages for 5 minutes, the server will send a disconnect signal (this is to prevent forgotten/leaked connections). The connection will be automatically reestablished if the client is still active (e.g. the browser tab is still open).
POST
/api/realtime
Sets new active client’s subscriptions (and auto unsubscribes from the previous ones).
If Authorization header is set, will authorize the client SSE connection with the associated user or superuser.
Body Parameters
| Param | Type | Description |
|---|---|---|
| Required clientId | String | ID of the SSE client connection. |
| Optional subscriptions | Array | The new client subscriptions to set in the format: COLLECTION_ID_OR_NAME/* or COLLECTION_ID_OR_NAME/RECORD_ID. You can also attach optional query and header parameters as serialized json to a single topic using the options query parameter, e.g.: COLLECTION_ID_OR_NAME/ RECORD_ID ? ={"query":{"abc": "123"}, "headers":{"x-token":"..."}} Leave empty to unsubscribe from everything. |
Body parameters could be sent as JSON or multipart/form-data.
Responses
null
{"status": 400, "message":"Something went wrong while processing your request.", "data":{"clientId":{"code": "validation_required", "message":"Missing required value."}}}
{"status": 403, "message":"The current and the previous request authorization don't match.", "data":{}}
{"status": 404, "message":"Missing or invalid client id.", "data":{}}
All of this is seamlessly handled by the SDKs using just the subscribe and unsubscribe methods:
import from 'pocketbase'; const = new PocketBase('http://127.0.0.1:8090');...// (Optionally) authenticate await. collection('users'). authWithPassword('test@example.com', '1234567890');// Subscribe to changes in any record in the collection. collection('example'). subscribe('*', function(e){. log(.);. log(.);},{/* other options like expand, custom headers, etc. */});// Subscribe to changes only in the specified record. collection('example'). subscribe('RECORD_ID', function(e){. log(.);. log(.);},{/* other options like expand, custom headers, etc. */});// Unsubscribe. collection('example'). unsubscribe('RECORD_ID');// remove all 'RECORD_ID' subscriptions. collection('example'). unsubscribe('*');// remove all '*' topic subscriptions. collection('example'). unsubscribe();// remove all subscriptions in the collection
import'package:pocketbase/pocketbase.dart''package:pocketbase/pocketbase.dart'; final = PocketBase('http://127.0.0.1:8090''http://127.0.0.1:8090');...// (Optionally) authenticate await. collection('users' 'users'). authWithPassword('test@example.com''test@example.com', '1234567890' '1234567890');// Subscribe to changes in any record in the collection. collection('example' 'example'). subscribe('*''*',(){print(.); print(.);},/* other options like expand, custom headers, etc. */);// Subscribe to changes only in the specified record. collection('example' 'example'). subscribe('RECORD_ID' 'RECORD_ID',(){print(.); print(.);},/* other options like expand, custom headers, etc. */);// Unsubscribe. collection('example' 'example'). unsubscribe('RECORD_ID' 'RECORD_ID');// remove all 'RECORD_ID' subscriptions. collection('example' 'example'). unsubscribe('*''*');// remove all '*' topic subscriptions. collection('example' 'example'). unsubscribe();// remove all subscriptions in the collection