WebSocket API¶
The WebSocket API provides real-time event streaming for workbook updates, job progress, and notifications.
Overview¶
CalcBridge WebSocket supports:
- Workbook Events: Real-time updates when workbook data changes
- Job Tracking: Live progress for export, reconciliation, and calculation jobs
- Notifications: Instant notification delivery
- Room-Based Subscriptions: Subscribe to specific resource channels
Connection¶
Main WebSocket Endpoint¶
Authentication is via JWT token passed as a query parameter.
Specialized Endpoints¶
| Endpoint | Description |
|---|---|
/ws | General-purpose connection with manual room subscription |
/ws/workbooks/{workbook_id} | Auto-subscribed to workbook events |
/ws/jobs/{job_id} | Auto-subscribed to job progress |
/ws/notifications | Auto-subscribed to user notifications |
Authentication¶
All WebSocket connections require a valid JWT token:
Room Types¶
| Room Pattern | Description |
|---|---|
workbook:{tenant_id}:{workbook_id} | Workbook-specific updates |
job:{job_id} | Job/task progress updates |
notifications:{user_id} | User notification delivery |
Workbook Events¶
Events received when connected to /ws/workbooks/{workbook_id}:
| Event | Description |
|---|---|
workbook.status_changed | Workbook processing status changed |
workbook.processing_started | Processing has begun |
workbook.processing_progress | Progress update with percentage |
workbook.processing_completed | Processing finished successfully |
workbook.processing_failed | Processing encountered an error |
sheet.data_updated | Sheet data has been modified |
Example Event¶
{
"type": "workbook.processing_progress",
"payload": {
"workbook_id": "550e8400-e29b-41d4-a716-446655440000",
"progress": 75,
"message": "Processing sheet 3 of 4"
},
"timestamp": "2026-01-25T10:30:05Z"
}
Job Events¶
Events received when connected to /ws/jobs/{job_id}:
| Event | Description |
|---|---|
job.started | Job execution has begun |
job.progress | Progress update |
job.completed | Job finished successfully |
job.failed | Job encountered an error |
job.cancelled | Job was cancelled |
job.retrying | Job is being retried |
Example Event¶
{
"type": "job.completed",
"payload": {
"job_id": "job_xyz789",
"result": {
"rows_processed": 150,
"duration_ms": 3200
}
},
"timestamp": "2026-01-25T10:30:15Z"
}
Notification Events¶
Events received when connected to /ws/notifications:
| Event | Description |
|---|---|
notification | Standard notification |
alert | Urgent alert notification |
Example Event¶
{
"type": "notification",
"payload": {
"id": "notif_abc123",
"title": "Export Complete",
"message": "Your XLSX export is ready for download",
"priority": "normal"
},
"timestamp": "2026-01-25T10:30:00Z"
}
Error Handling¶
| Error | Description |
|---|---|
| Connection closed (4001) | Invalid or expired JWT token |
| Connection closed (4003) | Insufficient permissions for requested room |
| Connection closed (4008) | Connection timeout (no heartbeat) |
Related Documentation¶
- Real-time - Real-time feature documentation
- Notifications API - Notification management