Renew token → Before expiration (every ~25 minutes)
Step-by-step guide
Step 1 — Obtain a WebSocket token
Call the /v1/ws/new endpoint to generate a new WebSocket token.
The response contains everything you need to connect:
Save the token and use the server URL to connect. Note the expires_at timestamp — you will need to renew the token before this time.
Step 2 — Connect to WebSocket
Use the server URL from the previous response to establish a WebSocket connection:
Step 3 — Subscribe to a channel
Once connected, subscribe to the channels you need. For example, to receive all match events on the MAIN channel:
You can also subscribe to a specific match or league:
The server confirms each subscription:
Step 4 — Handle events
Process incoming messages based on their type:
Step 5 — Renew token before expiration
WebSocket tokens expire after approximately 25 minutes. You must call the /v1/ws/renew endpoint before the token expires to keep your connection alive.
Best practice: set a timer to renew 5 minutes before the expires_at timestamp.
Complete example
A full working example combining all steps: obtain token, connect, subscribe, handle events, keep-alive ping, and token renewal.
MAIN_REALTIME channel (MEGA plan 🟩 only)
If you subscribe to the MAIN_REALTIME channel, the messages contain IDs that are specific to the realtime data source and differ from the standard REST API IDs. To map these realtime IDs to the corresponding REST IDs, use the following endpoints:
// Subscribe to a specific match
ws.send(JSON.stringify({
"action": "subscribe",
"channel": "MAIN",
"scope": "match",
"id": "b01d28ac92221034"
}));
// Subscribe to a specific league
ws.send(JSON.stringify({
"action": "subscribe",
"channel": "MAIN",
"scope": "league",
"id": "f2b16fa54cb525d"
}));