GET /agents/states returns empty array for active agent

I’m trying to pull real-time agent state data for my WFM adherence script. The agent is definitely logged in and taking calls. I can see the green dot in the dashboard. But when I hit the API, I get nothing.

Here is the call:

GET /api/v2/analytics/queues/summary?intervalCount=1&intervalUnit=minutes&startDate=2023-10-27T08:00:00.000Z&endDate=2023-10-27T09:00:00.000Z&granularity=minutes

Wait, that’s the wrong endpoint. I meant the states endpoint:

GET /api/v2/analytics/agents/realtime?agentIds=12345678-1234-1234-1234-123456789012

The response is a 200 OK, but the agents array is empty.

{
 "agents": [],
 "startTime": "2023-10-27T16:00:00.000Z",
 "endTime": "2023-10-27T16:00:05.000Z"
}

I’ve checked the OAuth token. It has analytics:read scope. The agent ID is correct. I copied it from the URL of the agent profile page.

Is there a delay in the realtime API? Or do I need a different scope to see the actual state? I tried adding interaction:read but that didn’t change anything.

Also, I noticed the documentation says this endpoint might return empty if the agent is in a queue that isn’t monitored. We are using custom queues. Could that be it?

Here is the Python snippet I am using to verify the token and make the call:

from genesyscloud import api_client, analytics_api

client = api_client.ApiClient(configuration)
analytics = analytics_api.AnalyticsApi(client)

try:
 resp = analytics.get_analytics_agents_realtime(
 agent_ids="12345678-1234-1234-1234-123456789012",
 start_time="2023-10-27T16:00:00.000Z",
 end_time="2023-10-27T16:00:05.000Z"
 )
 print(resp.agents)
except Exception as e:
 print(e)

Nothing in the logs. Just empty list.