Trying to pull real-time queue metrics-specifically waitingCount and agentsAvailable-via the Statistics API v2. I’m hitting GET /api/v2/analytics/queue/details with an interval of now to get the current snapshot. The request returns a 200 OK, but the JSON structure is dense and I’m having trouble mapping the nested objects to my Kotlin data classes.
Here’s the relevant snippet from the response payload:
{
"details": [
{
"queueId": "abc-123",
"queueName": "Support Tier 1",
"metricName": "conversation.waiting",
"metricValue": 5,
"timestamp": "2023-10-27T14:30:00.000Z"
},
{
"queueId": "abc-123",
"queueName": "Support Tier 1",
"metricName": "conversation.available",
"metricValue": 12,
"timestamp": "2023-10-27T14:30:00.000Z"
}
]
}
The issue is that metricValue seems to be a Double in the schema, but I need integer counts. Casting 5.0 to Int works, but it feels brittle. Also, the details array can contain multiple entries per queue if I request multiple metrics. I’m currently filtering the list in Kotlin:
val waiting = details.firstOrNull { it.metricName == "conversation.waiting" }?.metricValue?.toInt()
This works for a single queue, but scaling this to monitor 50+ queues via a single API call makes the payload huge and parsing slow. Is there a way to filter the metrics at the API level using the metricNames query parameter? I tried metricNames=conversation.waiting,conversation.available, but the response still includes other default metrics like conversation.active.
Also, the timestamp field is often a few seconds behind now. Is this expected latency for the Statistics API, or am I missing a configuration flag for real-time push? The documentation mentions interval but doesn’t clarify the refresh rate for now.
Any pointers on optimizing the query or handling the data types would be appreciated. I’m also seeing occasional 503s during peak load, which is concerning for a real-time dashboard.