Calculating Service Level percentage from Analytics API interval data

I’m trying to calculate the Service Level percentage (calls answered within 20 seconds) using the raw interval data from the Analytics API. The endpoint is POST /api/v2/analytics/conversations/queues/query. I have the access token and the scopes are correct, so I’m getting data back. The problem is the aggregation. The API returns a list of intervals, each with answer and abandon counts, but no explicit “within SLA” count. I need to derive the percentage from the raw intervals.

Here’s the request body I’m sending:

{
 "groupBy": ["interval"],
 "interval": "PT1H",
 "dateFrom": "2023-10-01T00:00:00Z",
 "dateTo": "2023-10-01T01:00:00Z",
 "filters": {
 "groups": {
 "ids": ["queue-id-123"]
 },
 "types": ["voice"]
 },
 "metrics": ["answer", "abandon", "wait"]
}

The response gives me something like this for each interval:

{
 "interval": "2023-10-01T00:00:00Z",
 "answer": 50,
 "abandon": 5,
 "wait": 12000
}

I’m assuming wait is the average wait time in milliseconds. If I sum up the answer counts where wait <= 20000, that should give me the number of calls answered within SLA. Then I divide that by the total answer + abandon count? Or is it just total answer? I’m confused about the denominator. The docs mention serviceLevel metric, but it’s not in the interval breakdown. I want to calculate it myself to get a precise percentage per hour.

Is this the right approach? I’ve tried summing the answer counts where wait <= 20000 and dividing by the total answer count, but the percentage seems off compared to the dashboard. Maybe the wait metric is median, not average? I need to know how to correctly aggregate these intervals to get a Service Level percentage. Any code examples or logic checks would be helpful. I’m using Python to process the JSON response.

The API doesn’t give you SLA directly because it depends on your specific queue settings. You’ll need to pull the service_level threshold from the queue config first, then filter the intervals. Here’s how I handle it in Terraform exports:

data "genesyscloud_routing_queue" "main" {
 name = "Support"
}

# Use data.genesyscloud_routing_queue.main.service_level_seconds for your calc

You’ll have to do the math in your application logic. The interval data just gives you the raw counts.