Genesys Cloud Web Messaging: Closing active sessions via API

Our infrastructure team is trying to automate the cleanup of stale Web Messaging sessions using the CX as Code provider in Terraform. We have a script that identifies inactive guest sessions, but we are struggling to find a reliable API endpoint to programmatically terminate them from the backend.

The documentation for the Conversations API mentions DELETE /api/v2/conversations/messaging/{conversationId}, but this requires us to know the internal conversation ID, which is not exposed to the guest SDK in a way that our backend service can easily retrieve. We tried using the guest token to call the endpoint, but we get a 403 Forbidden response.

Is there a supported method to close a session using just the guestId or contactId? Or do we need to implement a webhook listener to capture the conversation ID on creation? Here is the current Terraform resource we are using to manage the application:

resource "genesyscloud_webmessaging_application" "main" {
 name = "Support Portal"
 description = "Main web messaging app"
}

Any pointers on the correct API flow would be appreciated.