Genesys Cloud Guest API WebSocket connection drops immediately after `connect`

Trying to build a custom chat UI in Kotlin using the raw Guest API instead of the widget. I get a valid accessToken and hit wss://webmessaging.genesyscloud.com/api/v2/webmessaging/guest/conversations but the socket closes with code 1006 right after the initial handshake. My connect payload matches the docs exactly. Here’s the JSON I’m sending: {"type":"connect","accessToken":"<token>"}. Am I missing a header or is the endpoint wrong for the latest API version?

The endpoint you are using is for the public guest API. It expects a specific header setup that most standard websocket libraries don’t add by default. The 1006 error usually means the server closed the connection without a proper close frame, which often happens when the Sec-WebSocket-Protocol header is missing or incorrect.

You need to include the Sec-WebSocket-Protocol header with the value guest-protocol-v1. Also, make sure your Origin header matches the domain in your accessToken if you generated it via the webmessaging guest login flow. If you are using a raw Kotlin WebSocket client, you likely have to set these headers manually before connecting.

Here is how the headers should look in a curl-like representation to verify your setup:

curl -i -N \
 -H "Connection: Upgrade" \
 -H "Upgrade: websocket" \
 -H "Sec-WebSocket-Version: 13" \
 -H "Sec-WebSocket-Protocol: guest-protocol-v1" \
 -H "Origin: https://your-app-domain.com" \
 -H "User-Agent: Mozilla/5.0" \
 -H "Accept: */*" \
 "wss://webmessaging.genesyscloud.com/api/v2/webmessaging/guest/conversations"

In Kotlin, if you are using khttp or a similar library, ensure you pass the map of headers correctly. The connect message itself is fine, but the handshake fails before that message is even processed if the protocol header is wrong. Check your client implementation to see if it supports custom subprotocols.