WebSockets#

WebSockets are a crucial element of the Cherry API, enabling frontend interface integration and synchronization.

Connection#

To connect to any WebSocket endpoint, you must include your authentication token as an access_token parameter when establishing the connection. Please note that if your token expires during an active session, you will be disconnected with error code 4401.

Disconnection codes#

Below is a short guide to common disconnect codes shared by each websocket in the application.

CodeTitleDescription
1000Undefined/Custom-
1011Internal server errorReturned on server-side exception.
4401UnauthorizedIndicates issues with the user authentication token. Often returned on token validation failure or expiration.
4403ForbiddenResource requires elevated permissions to access.

Machine WebSockets#

The following WebSocket endpoints provide real-time machine data streams within the application:

  • /ws/machines/subscribed – streams data for machines explicitly subscribed to by the client
  • /ws/machines/account – streams data for all machines owned by or assigned to the currently authenticated user
  • /ws/machines/global – streams data for all machines available in the system. Requires VIEW_ALL_VMS permission.

Each message follows the unified format below:

{
    "uuid": "Unique message identifier",
    "type": "Message type",
    "body": "Message body content",
    "timestamp": "ISO 8601 Timestamp"
}

Message types#

The following table describes all WebSocket message types, their payload formats, trigger conditions, and purpose.

TypeBody formatSent onDescription
CREATEMachinePropertiesPayloadSuccessful machine creationStatic properties of a newly created machine.
DELETE{ uuid }Successful machine deletionIdentifies a removed machine.
DATA_STATICdict[UUID, MachinePropertiesPayload]WebSocket connectionSuccessful properties modificationStatic properties keyed by machine UUID. Full set on connect; single entry on update.
DATA_DYNAMICdict[UUID, MachineStatePayload]WebSocket connectionEvery 1sDynamic machine state keyed by machine UUID.
DATA_DYNAMIC_DISKSdict[UUID, MachineDisksPayload]WebSocket connectionWebSocket connectionEvery 2 minDisk state data keyed by machine UUID.
DATA_DYNAMIC_CONNECTIONSdict[UUID, MachineConnectionsPayload]WebSocket connectionEvery 10sNetwork connection data keyed by machine UUID.
BOOTUP_START{ uuid }Bootup initiatedIndicates boot process start.
BOOTUP_SUCCESS{ uuid }Bootup completedIndicates successful boot.
BOOTUP_FAIL{ uuid, error }Bootup failureIndicates failed boot with error details.
SHUTDOWN_START{ uuid }Shutdown initiatedIndicates shutdown process start.
SHUTDOWN_SUCCESS{ uuid }Shutdown completedIndicates successful shutdown.
SHUTDOWN_FAIL{ uuid, error }Shutdown failureIndicates failed shutdown with error details.

Important Notes#

/ws/machines/subscribed#

  • When a subscribed machine is deleted, a DELETE message is sent. Dynamic broadcasts for that machine stop, but the WebSocket connection remains open.
  • CREATE messages are not emitted on this WebSocket.