Calculating Service Level from Analytics API interval data

Hey everyone,

I’m trying to build a custom service level report using the Analytics API instead of relying on the out-of-the-box widgets. The goal is to pull raw interval data for a specific queue and calculate the percentage of conversations answered within 20 seconds.

I’m hitting GET /api/v2/analytics/details/queues/summary with a 1-hour granularity. The response gives me buckets for answered, abandoned, and missed, but it doesn’t explicitly give me a “service level” field. I have to derive it.

Here’s the JSON payload structure I’m seeing for a single interval:

{
 "granularity": "1h",
 "intervals": [
 {
 "start": "2023-10-27T10:00:00.000Z",
 "end": "2023-10-27T11:00:00.000Z",
 "metrics": {
 "answered": {
 "count": 150,
 "serviceLevel": 0.85 // Wait, is this cumulative?
 },
 "abandoned": {
 "count": 10
 }
 }
 }
 ]
}

I see a serviceLevel metric inside the answered object, but I’m not sure if that’s the percentage for that specific hour or a running total. Also, how do I handle the waitTime distribution? The API doesn’t seem to return the exact wait time for each call in this endpoint, just the aggregate counts.

I’m thinking I need to sum up the answered count where waitTime <= 20s and divide by the total answered count. But the interval data doesn’t break down wait times into buckets like “0-20s”, “20-60s”, etc. in this specific endpoint. I’ve checked the conversations/details/query endpoint, but that’s paginated and slow for large datasets.

Is there a better endpoint to get wait time distributions? Or am I supposed to calculate this manually from the serviceLevel metric provided? I’m worried about double-counting if I just sum the hourly percentages.

Any pointers on the correct formula or endpoint? I’m stuck on the math part.

The docs state: “The details API returns aggregated metrics for the specified interval.” You’re probably overcomplicating the math. Service level is just answered calls within the threshold divided by total handled. You don’t need to parse every bucket manually.

Here’s how I usually grab the token first, then hit the endpoint. Note the scope analytics:view.

import requests

# 1. Get Token
token_resp = requests.post("https://api.mypurecloud.com/oauth/token",
 headers={"Content-Type": "application/x-www-form-urlencoded"},
 data={
 "grant_type": "client_credentials",
 "client_id": "YOUR_CLIENT_ID",
 "client_secret": "YOUR_SECRET"
 })
token = token_resp.json()["access_token"]

# 2. Get Queue Details
headers = {"Authorization": f"Bearer {token}"}
params = {
 "dateRangeType": "thisWeek",
 "intervalUnit": "hour",
 "view": "AcdInterval",
 "metrics": "answerRate,serviceLevel"
}
resp = requests.get("https://api.mypurecloud.com/api/v2/analytics/details/queues/{queueId}", 
 headers=headers, params=params)

Check the serviceLevel metric directly in the response. It’s already calculated. No need to reinvent the wheel.