I’ve been wrestling with the CXone Reporting API v2 endpoint for agent state history. The goal is straightforward. I need to pull a list of state changes for a specific user over the last 24 hours. I’m using the standard OData query syntax that the docs recommend.
The weird part is that the request completes successfully with a 200 OK status. No errors. No 400s. But the items array in the response is always empty. I’ve verified the user ID is correct and the user was definitely logged in during the requested window.
Here is the request structure I am sending via Postman and also in my Python script using requests.
import requests
import datetime
# Calculate time window
end_time = datetime.datetime.utcnow()
start_time = end_time - datetime.timedelta(hours=24)
start_iso = start_time.strftime('%Y-%m-%dT%H:%M:%S.000Z')
end_iso = end_time.strftime('%Y-%m-%dT%H:%M:%S.000Z')
user_id = "12345678-1234-1234-1234-123456789012"
url = f"https://api.niceincontact.com/reporting/api/v2/query/agent-state-history"
headers = {
"Authorization": "Bearer <my_valid_token>",
"Content-Type": "application/json"
}
payload = {
"aggregation": "NONE",
"intervalType": "NONE",
"where": [
{
"field": "user.id",
"op": "eq",
"value": user_id
},
{
"field": "interval.startTime",
"op": "gte",
"value": start_iso
},
{
"field": "interval.endTime",
"op": "lte",
"value": end_iso
}
],
"groupBy": [],
"sorts": [
{
"field": "interval.startTime",
"order": "desc"
}
],
"limit": 100
}
response = requests.post(url, json=payload, headers=headers)
print(response.status_code)
print(response.json())
The response body looks like this:
{
"count": 0,
"hasMore": false,
"items": []
}
I’ve tried swapping the date fields. I tried using interval.startTime vs date. I even tried broadening the window to 7 days just to be sure. Still nothing.
Is there a specific permission required on the OAuth token that isn’t obvious? I have reporting:read and reporting:write. The token works fine for other reporting queries like conversation details.
Maybe I’m missing a subtle syntax rule in the where clause for the agent-state-history object type specifically. The docs show examples for agent-activity but not this exact endpoint structure.
I’m stuck on this one.