I’m trying to grab the last 24 hours of agent state history for a custom desktop widget we’re building. The goal is just to show agents when they were last logged in or away, but the v2 reporting endpoint keeps handing back empty data arrays. Auth isn’t the bottleneck here since the OAuth flow is sorted and tokens refresh fine.
Here’s the fetch call I’m running inside the client app:
const response = await fetch('https://api.niceincontact.com/v2/reporting/agents/states/interval', { method: 'POST', headers: { 'Authorization': Bearer ${token}, 'Content-Type': 'application/json' }, body: JSON.stringify({ dateFrom: '2024-05-15T08:00:00Z', dateTo: '2024-05-16T08:00:00Z', groupBy: 'agentId', interval: 'PT1H', select: ['agentId', 'stateName', 'duration'] }) });
The request goes through with a 200 OK, but the payload just has agents: []. I checked the OData filters and tried swapping groupBy to interval, same result. The docs mention that state history aggregates roll up differently depending on the granularity, so I’m wondering if the interval parameter is clashing with the date range. Also, the select array might need specific metric names instead of raw column headers.
We’ve tested this in staging with a live agent ID and it still returns nothing. The endpoint seems strict about timezone handling too, since we’re running out of London but the API expects UTC. I tried appending ?timeZone=Europe/London to the query string but that just triggers a 400 error about invalid parameters.
The SDK wrapper for reporting feels pretty thin compared to the telephony methods. Probably just missing a required filter or a specific metric alias.