Setting wrap-up code via API after conversation ends with Client App SDK

Is there a reliable way to set the wrap-up code programmatically right after an interaction ends using the Client App SDK?

I am building a custom agent desktop extension. The goal is to automatically apply a specific wrap-up code based on some business logic we run in the background. The conversation ends normally, but I want the system to handle the wrap-up step without the agent clicking anything.

I tried calling the REST API endpoint directly from within the SDK context. I used the genesyscloud.platformClient object to make the call. Here is the code snippet I am using:

const wrapUpData = {
 "wrapup": {
 "code": "WRAP_SUCCESS",
 "comment": "Auto-wrapped by extension"
 }
};

const response = await genesyscloud.platformClient.conversationsApi.postConversationWrapup(conversationId, wrapUpData);

The issue is that the API returns a 409 Conflict error. The error message says “Conversation is not in a state that allows wrap-up”. This happens even though I am calling it immediately after the conversation:updated event fires with the status ended.

I checked the conversation state in the debug console. It shows ended but not wrap-up. I thought the state transition was automatic. Maybe I need to wait for a specific event? Or is the Client App SDK not the right place to do this?

Also, I noticed that if I manually wrap up in the standard UI, the API call works fine. But programmatic calls seem to fail if the conversation is not explicitly in the wrap-up state. How do I force the conversation into that state or is there a different endpoint I should be using?

I don’t want to use Architect to do this because the logic is too complex for a simple data action. I need this to happen in the client-side extension.

What is the correct sequence of API calls to achieve this? I have read the docs on Interaction Control but it’s not clear if the Client App SDK has the right permissions for this specific action.