I’m pulling raw interval data from /api/v2/analytics/queues/{queueId}/data using the Python SDK. The response gives me offerCount and handleCount for each bucket, but I’m struggling to map these to a standard Service Level percentage. The docs are vague on whether handleCount includes abandoned calls or just answered ones within the threshold.
Here’s the aggregation logic I’ve got so far. Am I missing a filter or a specific metric field to get the accurate SL%? The numbers just don’t match the dashboard.
for interval in data['items']:
total += interval['metrics']['offerCount']
handled += interval['metrics']['handleCount']
handleCount is just answered calls. You need to sum waitTime intervals where the time is less than your SLA threshold, then divide by total offerCount. The SDK doesn’t do this math for you. Here’s the quick Node snippet to get that percentage:
const slp = (intervals, thresholdMs) => {
const answeredInTime = intervals.reduce((sum, i) => sum + (i.waitTime < thresholdMs ? i.handleCount : 0), 0);
return (answeredInTime / intervals.reduce((sum, i) => sum + i.offerCount, 0)) * 100;
};
’s logic is sound for the math, but you’ll run into trouble with the data granularity. The Analytics API buckets by interval size (usually 15 mins or 1 hour depending on the view), so i.waitTime isn’t a single value per call. It’s the bucket midpoint or range. Summing based on a midpoint check will skew your SL% if calls are clustered at the edge of the bucket.
You don’t actually need to do that manual reduction in Python. The SDK exposes metricId filters that let the platform do the aggregation. You can request serviceLevelPercentage directly if you set the intervalSize and groupBy correctly. It’s cleaner and avoids the “abandoned call” ambiguity entirely since the platform metric excludes them from the denominator by default.
Here’s how you structure the query using the Python SDK. Notice the metricId array. We pull offerCount and serviceLevelPercentage directly. The platform calculates the percentage based on your queue’s defined service level threshold (e.g., 20 seconds).
from purecloudplatformclient_v2 import AnalyticsApi, IntervalType
# Assuming 'api_instance' is your configured AnalyticsApi object
queue_id = "your-queue-id-here"
# Define the metrics we want.
# 'serviceLevelPercentage' handles the threshold logic for us.
metric_ids = ["offerCount", "serviceLevelPercentage"]
# Build the query body
body = {
"view": "queue",
"intervalSize": "15min", # Adjust based on your needs
"groupBy": ["queue"],
"metricIds": metric_ids,
"dateFrom": "2023-10-01T00:00:00.000Z",
"dateTo": "2023-10-02T00:00:00.000Z"
}
try:
# Call the analytics endpoint
response = api_instance.post_analytics_queues_data(
queue_id=queue_id,
body=body
)
# Iterate through the results
for result in response.results:
for bucket in result.buckets:
# bucket.metrics contains the calculated values
slp = bucket.metrics.get("serviceLevelPercentage")
offers = bucket.metrics.get("offerCount")
print(f"Interval: {bucket.start}, SL%: {slp}, Offers: {offers}")
except Exception as e:
print(f"Error: {e}")
If you really need custom thresholds that differ from the queue configuration, stick to the manual calculation but ensure you’re summing handleCount where the bucket’s waitTime range is fully within your limit. Partial overlaps are messy. Most people just align their reporting with the queue’s native SL threshold to avoid this headache.