GET /agents/states returning empty array for logged in rep

The compliance export hits GET /agents/states and just returns an empty array even though the rep’s logged in. We’ve verified the OAuth token works for user lookups but this endpoint keeps dropping the active state. Routing rules are set to standard queue and the orgId matches. Response body looks like this:
{
“items”: ,
“totalCount”: 0
}
Not sure what’s blocking the state sync.

You’re likely hitting a scope mismatch or querying the wrong resource type. The /agents/states endpoint isn’t the standard way to check if a rep is logged in or available. That endpoint is more about the definitions of the states, not the current status of users. If you want to see if a rep is active, you need to query the user’s current routing status.

The common gotcha here is assuming agents equals users in the API context. They don’t always map directly in the way you’d expect for real-time status. You need to use the Users API instead. Specifically, you want to get the user by ID and check their routingStatus.

Here’s how you’d do it with the Python SDK, which is pretty straightforward:

from purecloudplatformclientv2 import RoutingApi, UsersApi

# Initialize clients
routing_api = RoutingApi(configuration)
users_api = UsersApi(configuration)

# Get the user first
user = users_api.get_user(user_id="your_user_id_here")

# Check the routing status
if user.routing_status and user.routing_status.state:
 print(f"Rep is in state: {user.routing_status.state.name}")
 print(f"Is available: {user.routing_status.is_available}")
else:
 print("Rep is not logged in or state is unclear.")

Make sure your OAuth token has the view:users and view:routing scopes. Without those, you’ll get empty results or permission errors, even if the token itself is valid for other endpoints. Also, double-check that the user actually has a routing profile assigned. If they don’t, they won’t show up with a valid state.

It’s easy to mix up the endpoints because the naming is similar. The agents/states endpoint is really for getting the list of available states (like “Available”, “Busy”, “Break”) that your org has configured, not who is in them. Switching to the user lookup should give you the actual live data you need for your compliance export.

Just remember to handle the case where routing_status might be null if the rep is offline. You’ll want to add a check for that before trying to access .state.