Trying to build a custom SLA metric using the JS SDK. I’m pulling raw interval data from /api/v2/analytics/queues/summary with groupby: interval. The JSON returns offeredCount and answerCount, but I can’t find a direct serviceLevel field in the interval buckets.
Should I calculate (answerCount / offeredCount) * 100 manually for each bucket, or is there a specific metric I’m missing in the request payload? The docs are vague on this.
You’re missing the serviceLevel metric in your request body. The endpoint doesn’t return it by default unless you explicitly ask for it in the metrics array. Also, answerCount alone isn’t enough for SLA. You need serviceLevel which represents the count of offers answered within the defined service level target.
Here’s what the payload should look like. Note the metrics array includes serviceLevel and offeredCount.
var request = new QueueSummaryQueryRequest
{
GroupBy = new[] { "interval" },
Metrics = new[] { "serviceLevel", "offeredCount", "answerCount" },
Interval = "PT1H",
DateFrom = DateTimeOffset.UtcNow.AddDays(-1).ToString("O"),
DateTo = DateTimeOffset.UtcNow.ToString("O"),
Entities = new[]
{
new QueueEntity
{
Id = "your-queue-id-here"
}
}
};
var result = await platformClient.AnalyticsApi.PostAnalyticsQueuesSummary(request);
When you iterate through result.Entities, each entity will have a Metrics property. You’ll see something like this in the JSON response for each interval bucket:
{
"id": "2023-10-27T10:00:00.000Z",
"metrics": {
"serviceLevel": {
"value": 45
},
"offeredCount": {
"value": 50
}
}
}
The calculation is (serviceLevel.value / offeredCount.value) * 100. If offeredCount is 0, you’ll get a divide by zero error, so handle that case. The docs mention this in the QueueSummaryQueryRequest section under metrics description, but it’s easy to miss if you’re just looking at the response schema.
Don’t just add serviceLevel to metrics. That metric is already a percentage, so you’ll be dividing percentages instead of counts. Stick to offeredCount and answeredCount if you want raw numbers.