Stumbled on a weird bug today with the CXone REST API where GET /api/v2/agents/states returns an empty array for an agent I know is currently logged in and handling calls. This is breaking my React Native app’s presence indicator logic.
I am using the CXone JavaScript SDK (v5.2.1) to fetch the state. The auth token is valid, and I can successfully call GET /api/v2/agents/{agentId}/wrapupcodes, so permissions aren’t the issue. The endpoint just refuses to list the agent in the active states.
Here is the config I am using for the SDK initialization:
platform:
api_url: "https://mypurecloudinstance.custhelp.com"
client_id: "my-app-client-id"
scope:
- "agent-states:read"
- "agents:read"
- "routing:read"
I tried calling the endpoint directly via curl to rule out SDK quirks:
curl -X GET "https://mypurecloudinstance.custhelp.com/api/v2/agents/states?agentId=12345678-1234-1234-1234-1234567890ab" \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIs..."
Response:
{
"pageSize": 20,
"pageNumber": 1,
"total": 0,
"firstUri": "/api/v2/agents/states?pageSize=20&pageNumber=1",
"lastUri": "/api/v2/agents/states?pageSize=20&pageNumber=1",
"nextUri": null,
"previousUri": null
}
The agent ID is correct. I verified it against GET /api/v2/users/me. The agent is definitely in the “Available” state in the desktop client. I checked the routing queue configuration, and the agent is assigned to the queue. I even tried forcing a state change by having the agent log out and back in, but the API still returns total: 0.
Is there a specific scope I am missing? Or does agent-states:read require additional permissions on the user profile? I am stuck because my app relies on this endpoint to sync the agent’s availability status to the mobile UI. Any help would be appreciated. I am losing my mind over this.