Realtime sockets
A realtime socket streams the same receipts as an event pull subscription, so you don’t need to poll. You attach existing pull subscriptions to the socket.
You need website_read and event_read, and every request must send an exact HTTPS Origin header.
-
Create a session.
Terminal window curl -s -X POST "$GATEWAY/api/v1/realtime/sessions" \-H "Authorization: Bearer $INSIDE_GATEWAY_TOKEN" \-H "Content-Type: application/json" \-H "Origin: https://app.example.com" \-d '{"website_ids":["web_4927_123"]}'The
201response containssession_idand a single-useticketthat expires within 30 seconds. -
Open the socket. Connect to
GET /api/v1/realtime/sessions/{session_id}/socketas a WebSocket with the sameOrigin. Within 5 seconds, send the ticket as the first text frame:{ "type": "auth", "ticket": "..." }An
auth.okframe confirms authentication. -
Attach a subscription.
{ "type": "subscription.open", "subscription_id": "sub_...", "cursor": "..." } -
Acknowledge each page. For every
subscription.page, sendsubscription.ackwith its exactnext_cursorwithin 30 seconds. -
Reconnect or close. Call
POST /api/v1/realtime/sessions/{session_id}/ticketsfor a reconnect ticket, andDELETE /api/v1/realtime/sessions/{session_id}to close the session.
Limits
Section titled “Limits”- Up to 20 sessions per installation, and up to 20 attached subscriptions per socket.
- Each page has at most 25 receipts, and frames are at most 64 KiB.
- Reconnecting replays from the last acknowledged cursor.
- Send
subscription.closeto detach a subscription.