I’m trying to programmatically end a web messaging conversation from our backend service. We have a custom adherence check that runs on a timer, and if an agent has been idle for too long, we want to force-close the active messaging sessions to reset their status.
I found the endpoint DELETE /api/v2/conversations/messaging/{conversationId} in the docs. It seems like the right place to go, but it’s not working as expected.
Here is the Python code I’m using to fetch the conversation ID and then attempt the deletion:
import requests
import os
headers = {
'Authorization': f'Bearer {os.getenv("GENESYS_TOKEN")}',
'Content-Type': 'application/json'
}
# Get active conversations for the agent
agent_id = "12345"
resp = requests.get(f'https://api.mypurecloud.com/api/v2/conversations/messaging?agentId={agent_id}', headers=headers)
conversations = resp.json()
if conversations['items']:
conv_id = conversations['items'][0]['id']
print(f"Closing conversation: {conv_id}")
# Attempt to close
delete_resp = requests.delete(f'https://api.mypurecloud.com/api/v2/conversations/messaging/{conv_id}', headers=headers)
print(f"Status: {delete_resp.status_code}")
print(f"Response: {delete_resp.text}")
The GET request works fine and returns the conversation ID. But when I hit the DELETE endpoint, I get a 404 Not Found error. The response body is just:
{"message":"Resource not found"}
I’ve double-checked the conversationId and it matches exactly what I got from the list response. I also tried passing a reason in the query string like ?reason=agentIdle, but that didn’t help.
Is there a different endpoint I should be using to close a messaging session? Or is there a specific permission my OAuth client needs? I’m a bit stuck here.