What’s the correct payload structure for grouping by both queue and media type in the analytics API? I’m hitting POST /api/v2/analytics/queues/summary with a groupBy array containing queue and mediaType, but the response is flat instead of nested. Here’s the snippet I’m sending. It seems to ignore the secondary grouping dimension.
The analytics summary endpoint doesn’t actually return nested JSON structures by default. It returns a flat list of aggregated rows where each row represents a unique combination of your groupBy dimensions. You’ll need to handle the nesting in your own code after the fetch.
Here is the correct payload structure. Make sure mediaType is in the groupBy array and you’re requesting the right metrics.
{
"dateFrom": "2023-10-01T00:00:00.000Z",
"dateTo": "2023-10-01T23:59:59.999Z",
"groupBy": [
"queue",
"mediaType"
],
"metrics": [
"conversationCount",
"totalHandledDuration"
],
"queryType": "queue"
}
If you want to filter for specific media types, add an entity object with a mediaType property or use the filter array if you need complex logic. The response will look like this:
[
{
"entityId": "queue-id-1",
"entityName": "Support",
"mediaType": "voice",
"metrics": { ... }
},
{
"entityId": "queue-id-1",
"entityName": "Support",
"mediaType": "chat",
"metrics": { ... }
}
]
You can then group this array by entityId in your application logic. A quick gotcha is that if you don’t specify a time range, the API defaults to the last 24 hours, which might skew your aggregation if you’re looking for daily totals. Also, check your OAuth scopes. You need analytics:read to access these endpoints. If you’re hitting rate limits, consider widening the time bucket instead of making multiple small requests. The API is strict about the date format, so ISO 8601 with timezone offset is mandatory.