We have a batch process that cleans up terminated agents. The script calls the Users API to remove the user object. The goal is to keep the historical interaction data for WFM reporting. The problem is the data gets orphaned or loses the agent name in the reports.
Here is the code snippet from our Python script:
def remove_agent(user_id):
url = f"https://mydomain.mypurecloud.com/api/v2/users/{user_id}"
headers = {"Authorization": f"Bearer {access_token}"}
response = requests.delete(url, headers=headers)
print(f"Status: {response.status_code}")
return response.status_code
The API returns a 204 No Content. The call succeeds. But when I query the WEM adherence data later, the agent.name field is null. The agent.id is still there, but the name is gone. This breaks our adherence reports. We need the name to match the historical logs.
I checked the documentation. It says deleting a user removes the user object. It does not say it deletes the interaction history. But the name link is broken. Is there a way to delete the user without breaking the name link? Or do I need to archive the user instead? The API does not have an archive endpoint. Only delete.
I tried setting the user to inactive first. I used a PATCH call to set status to inactive. Then I deleted the user. The result is the same. The name is null in the historical data. This is not acceptable for our compliance team. They need the full name in the reports.
Is there a different API call? Maybe a bulk update? Or a specific header I need to send? I looked at the Users API reference. Nothing about preserving name links on delete. The endpoint is /api/v2/users/{userId}. It is a simple DELETE request.
The timezone is US/Pacific. The data is from the last 90 days. The issue is consistent. Every deleted user loses the name in the reports. This is a big problem for our WFM metrics. We track adherence by agent name. If the name is missing, the report is useless.
I need a solution. Do I have to keep the user active? That seems wrong. They are terminated. But deleting them breaks the data. Is there a workaround? Maybe a custom attribute? Or a different way to link the data? I am stuck. Any ideas on how to handle this via the API? The current approach is failing. We need a reliable way to remove users without losing the historical context. The code is simple. The result is not. What am I missing? Is this a known issue? Or is there a best practice I am not following? I have checked the forums. No clear answer. Just questions like this one. I need a fix. Please help.