Setting wrap-up code via API after interaction ends returns 400

Hi everyone,

We are building a post-interaction workflow in New Relic to capture wrap-up codes from Genesys Cloud and trigger specific alerting policies. The goal is to programmatically set the wrap-up code immediately after the interaction status changes to ENDED.

I have been testing this using the Python SDK (genesyscloud). I’m listening for the interaction status change event, extracting the interactionId, and then attempting to update the interaction using the update_interaction method. I’m trying to set the wrapUpCode inside the attributes object.

Here is the relevant snippet of the code I’m running:

from genesyscloud.conversations import ConversationsApi

conversations_api = ConversationsApi(configuration)

# Payload structure I am sending
update_payload = {
 "attributes": {
 "wrapUpCode": "Sales Follow-up",
 "custom_field": "some_value"
 }
}

try:
 api_response = conversations_api.update_interaction(
 interaction_id=interaction_id,
 body=update_payload
 )
except Exception as e:
 print(f"Error: {e}")

The API call fails with a 400 Bad Request error. The error message returned is:

{
 "message": "Invalid interaction update request. Wrap-up codes cannot be set after interaction has ended.",
 "code": "invalid.request"
}

I’ve checked the documentation, and it seems like the standard update endpoint rejects changes to the wrap-up code once the interaction lifecycle has moved past the active state. I want to make sure I’m not missing a specific endpoint or a different payload structure that allows this.

Here is what I have tried so far:

  • Attempting to update the interaction via the API with the same payload.
  • Trying to set the wrap-up code in the participants array instead of the top-level attributes.
  • Checking if the wrapUpCode needs to be an ID rather than a string label (I tried both).

Is there a specific API call to set the wrap-up code after the fact, or is this strictly limited to the agent’s action in the UI or Architect? I need to automate this for our reporting pipeline.

Thanks.

Check your OAuth scopes first. The genesyscloud SDK usually handles token refresh, but if the underlying client doesn’t have interaction:interaction:write, you’ll get a 400 or 401 that looks like a validation error. It’s a sneaky one because the SDK doesn’t always throw a clear “permission denied” on the update call itself.

Also, pushing a wrap-up code via API after the interaction status is ENDED is tricky. Genesys Cloud often locks the disposition once the agent clicks “End” or the timeout hits. You might be fighting a race condition where the API call arrives milliseconds after the backend has already sealed the interaction record.

Instead of patching the interaction directly, try using the API to set the wrap-up code for the participant. It’s designed specifically for this. Here’s how it looks in Python:

from genesyscloud.platform.client import PlatformClient
from genesyscloud.interaction.models import WrapupCode

# Assuming you have your platform_client initialized
wrapup_code = WrapupCode(
 id="your-wrapup-code-id-here",
 name="Customer Requested Callback"
)

try:
 # Use the specific wrapup endpoint, not the general interaction update
 response = platform_client.conversations_api.set_participant_wrapup(
 conversation_id=conversation_id,
 participant_id=participant_id,
 body=wrapup_code
 )
 print(f"Wrap-up set successfully: {response}")
except Exception as e:
 print(f"Failed to set wrap-up: {e}")

Make sure your-wrapup-code-id-here is the actual UUID from your Genesys Cloud instance, not just the name. If you’re still hitting 400s, check the error body for invalid_state. That means the interaction is already finalized. You might need to hook into the interaction:status:changed event and fire the API call the moment it hits ENDED but before the final COMPLETE state locks it.