CXone Reporting API v2: Querying Agent State History with OData filter fails on time range

Trying to pull agent state history for the last 24 hours using the CXone Reporting API v2. We’ve got a hybrid setup here in Sydney and the reporting latency is annoying us, so we need accurate data for our hybrid platform dashboard.

I’m hitting /api/v2/reporting/agents/states with an OData filter. The docs say I should use $filter for the time range. Here’s the snippet I’m working with in Python:

import requests
import jwt

# ... auth setup omitted for brevity ...

headers = {
 'Authorization': f'Bearer {token}',
 'Accept': 'application/json'
}

params = {
 '$filter': 'startTime ge 2023-10-27T00:00:00Z and endTime le 2023-10-28T00:00:00Z',
 'expand': 'agent'
}

response = requests.get('https://api.us.niceincontact.com/api/v2/reporting/agents/states', headers=headers, params=params)
print(response.status_code)
print(response.text)

It’s returning a 400 Bad Request. The error payload looks like this:

{
 "code": "badRequest",
 "message": "Invalid OData filter syntax",
 "details": "Could not parse filter expression"
}

I’ve tried wrapping the dates in quotes, escaping the T, and even using dateTime casts. Nothing works. I’m used to Genesys Cloud APIs being a bit more forgiving with ISO 8601 strings, but this is strict.

Is there a specific format CXone expects for the $filter time comparisons? I’ve checked the Swagger spec but it’s vague on the exact string format for startTime and endTime in this endpoint. We need this for a compliance report that runs nightly. Any pointers on the correct syntax? I’ve been staring at this for an hour and it’s driving me nuts.