Trying to end a web messaging conversation from the backend using @genesyscloud/conversations-client. The patchConversation method requires a valid conversationId, but I’m only working with the guestId from the incoming webhook. There doesn’t seem to be a direct lookup or action to terminate the session without the internal ID. Is there a hidden endpoint or a specific payload structure for POST /api/v2/conversations/messaging/conversations that handles this?
Cause: You can’t patch a conversation you can’t find. The guestId is just a label. The system needs the internal UUID to lock and close the state. You have to search first.
Solution: Use the GET endpoint to find the active session. Then patch it.
const conversationsApi = platformClient.conversationsApi;
// 1. Find the conversation using the guest ID
const searchResults = await conversationsApi.getConversationsMessagingConversations({
"query": `guestId eq '${guestId}' and state eq 'connected'`
});
if (searchResults.entities.length > 0) {
const convId = searchResults.entities[0].id;
// 2. Close it
await conversationsApi.patchConversation({
conversationId: convId,
body: {
state: "closed",
closeReason: "agent closed"
}
});
}
Watch out for race conditions. If two agents try to close it at once, you’ll get a 409. Also, make sure your token has conversation:view and conversation:write scopes. The SDK handles the retry logic for 429s, but not for conflicts.