Skip to main content
POST
Set Websocket
Auth: TokenAccount or TokenInstanceRate limit: Global (100/min) • Idempotent: yes (upsert)

Description

Enables / disables the instance’s WebSocket channel and sets the event filter. Unlike the webhook, there is a single configuration per instance (no label). This endpoint does not open a connection, it only authorizes the later upgrade at GET /ws/:instance.

Examples

Enable everything

Turns on the WebSocket without any filter: since events is omitted, the client receives all 6 event types, and mediaBase64 stays false.

Narrow filter

Enables the WebSocket receiving only message.exchange and message.status and turns on mediaBase64: true so frames with media already include the binary content base64-encoded.

Disable the websocket

Turns off the WebSocket by sending enabled: false. The configuration row is preserved, events and mediaBase64 are cleared, and new connections to /ws/:instance start being rejected.

Success response

The response returns the websocket object with the configuration actually persisted (enabled, events, mediaBase64), mirrors the request body after the upsert. When enabled=false, events and mediaBase64 come back cleared; connections already open at /ws/:instance remain until closed naturally, but new connections start being rejected with 400.
200 OK

Path parameters

string
required
Instance name.

Headers

string
required
TokenAccount or TokenInstance.
string
required
application/json

Request body

boolean
required
Turns the WebSocket on/off. When false, events and mediaBase64 are cleared before saving.
string[]
default:"[]"
Filter. Empty array = receive all 6 types. Values must be in {message.exchange, message.status, call.update, group.flow, instance.state, label.update}.
boolean
default:"false"
When true, message.exchange events with media include media.base64 in the WS frames.

Notes

  • Does not persist events: WebSocket is ephemeral. If no one is connected at the moment of the event, it’s discarded (fast-path HasClients before any serialization work).
  • No retry: if the socket drops during send, the message is lost. For guaranteed delivery, use webhook.
  • enabled=false does not disconnect already-open clients: existing connections at /ws/:instance remain until closed naturally; new connections fail with 400.
  • No documented connection limit: each instance can have N simultaneous clients (broadcast). The hub keeps a 256-message buffer per client; slow clients are disconnected automatically.
  • Configuration at creation time: the same block can be passed to POST /api/instance/new via websocketEnabled, websocketEvents, websocketMediaBase64.

Errors

Envelope:

Next

Check WebSocket config

GET /api/events/getWebsocket/:instance

Connect via WebSocket

GET /ws/:instance, protocol, auth, reconnection.