Programmatically closing Web Messaging sessions from backend

Hey folks,
Trying to hang up on a Web Messaging guest from our backend service instead of waiting for them to leave. I’ve got the conversation ID but can’t figure out the right endpoint to trigger the close event. We’ve been poking around /api/v2/conversations/webmessaging/ but most calls seem to require an agent context which we don’t have here.

Does anyone know the specific API call or payload needed to force-close the session server-side? The docs are pretty vague on this.

The issue isn’t that you need an agent context to close the conversation, it’s that you’re looking at the wrong verb. You don’t need to “hang up” like a voice call. You just need to mark the conversation as closed.

In the .NET SDK, you use PureCloudPlatformClientV2.ConversationsApi.CloseConversation. This works with a Client Credentials flow, so no agent token required.

Here is the exact setup. First, make sure your app has the conversation:write scope. Then use this:

using Platform = GenesysCloud.Platform.Client;
using Api = GenesysCloud.Api.ConversationsApi;

// Assuming you have a valid IPlatformClient configured with Client Credentials
var platformClient = PlatformClientFactory.CreateClient();
var conversationsApi = new Api(platformClient);

try 
{
 // conversationId is the ID you already have
 var result = await conversationsApi.CloseConversation(conversationId);
 
 // result contains the updated conversation state
 Console.WriteLine($"Session {conversationId} closed successfully.");
}
catch (ApiException ex)
{
 Console.WriteLine($"Error closing conversation: {ex.Message}");
}

If you prefer raw HTTP, it is a POST to /api/v2/conversations/{conversationId} with an empty body {}. The docs are sometimes vague because they lump all conversation types together, but the close action is standard across voice, chat, and web messaging.

Just be aware that if the guest is still typing or the session is technically “active” in the frontend, the UI might show a disconnect error to them. It won’t prevent the backend from closing it though.