CXone Reporting API v2: Agent State History query timing out or returning empty for last 24h

We’re building a custom analytics dashboard using the Embeddable Client App SDK to show agent activity trends. Specifically, we need to pull agent state history for the last 24 hours. We’re hitting the CXone Reporting API v2 endpoint: /api/v2/analytics/reporting/agent-states/details.

I’ve tried constructing the $filter query parameter to handle the time window, but the results are inconsistent. Sometimes I get a 200 OK with an empty items array, other times the request just hangs and times out after 30 seconds.

Here’s the JavaScript code we’re using to build the request:

const startDate = new Date();
startDate.setHours(startDate.getHours() - 24);
const endDate = new Date();

const startTime = startDate.toISOString();
const endTime = endDate.toISOString();

const filter = `$filter=startTime ge ${startTime} and startTime le ${endTime}`;

const response = await fetch(`https://{{tenant}}.niceincontact.com/api/v2/analytics/reporting/agent-states/details?${filter}&$top=500`, {
 headers: {
 'Authorization': `Bearer ${accessToken}`,
 'Accept': 'application/json'
 }
});

I’ve verified the access token is valid by calling /api/v2/oauth2/tokeninfo and it returns successfully. The agent IDs we’re querying for are active and have logged in within the last hour.

I noticed in the documentation that startTime and endTime in the filter might refer to the report run time rather than the event time. Is that the case? If so, how do we filter by the actual state change timestamp?

Also, we’re seeing a lot of 400 Bad Request errors when we add $expand=agent to the query. The error payload looks like this:

{
 "status": 400,
 "title": "Bad Request",
 "detail": "Invalid filter expression"
}

What’s the correct syntax for filtering by a rolling 24-hour window in the agent state history report? We’ve tried using interval but that seems to only work for summary reports, not details.