Web Messaging: Programmatic session close from backend

What’s the right way to kill a web messaging session from the server side? The guest SDK has closeSession, but I need to trigger this via a backend API call after a specific event. Tried hitting DELETE /api/v2/conversations/messaging/{id}, but that just ends the conversation, leaving the widget in a ‘connected’ ghost state. Looking for the specific endpoint or payload to cleanly terminate the session on the client without refreshing the page.

Deleting the conversation resource doesn’t actually tell the guest SDK to shut down its WebSocket connection. That’s why you’re seeing the ghost state. The widget is still polling for new messages because the session isn’t explicitly closed from the client side.

You’ll need to push a command through the Conversation API. Specifically, you want to send a close command via the PATCH endpoint for that conversation. This signals the platform to terminate the session cleanly.

Here’s the payload structure you need:

PATCH /api/v2/conversations/messaging/{conversationId}

{
 "commands": [
 {
 "command": "close",
 "type": "guest"
 }
 ]
}

Make sure your OAuth token has the conversations:messaging:write scope. Once that patch goes through, the SDK receives the state change and drops the connection immediately. It’s a bit counterintuitive since you’d expect a DELETE to handle cleanup, but Genesys treats conversation lifecycle and session state separately here. The guest widget will update its UI to show the chat as ended without a full page reload.