I’m trying to set up a webhook listener for v2.analytics.conversation.aggregate events. The goal is to extract the average handle time for specific queues. The payload comes in fine, 200 OK on the endpoint, but the JSON structure is deeper than I expected.
Here’s a snippet of what I’m getting in the body:
{
"data": [
{
"id": "abc-123",
"interval": "PT1H",
"metrics": {
"conversationCount": 15,
"avgHandleTime": 120.5
}
}
]
}
I’m using Python with Flask. When I try data['metrics']['avgHandleTime'], it works for the first item, but I keep getting KeyError when the list is empty or if the structure shifts slightly between intervals.
I’m looping through the data array, but I’m not sure if I’m handling the nested dicts correctly. Is there a safer way to traverse this without crashing if a metric is missing? I’ve tried get(), but it returns None and then my downstream calculation fails. Any pointers on solid parsing for this specific event type?