Trying to wire up a webhook to trigger a Slack notification whenever a queue breaches its service level. I’ve got the webhook endpoint configured and the HTTP 200 OK is coming back, but the JSON payload I’m receiving doesn’t contain the actual SLA metrics I need to format the message.
I’m using the routing/queues/realtime/queueMetrics event trigger. Here’s the basic POST body I’m seeing:
{
"event": "queueMetrics",
"queueId": "123456",
"timestamp": "2023-10-27T10:00:00Z"
}
It’s just the ID and timestamp. No slaPercentage or breachedCount. I need those fields to construct the Slack block kit payload. I tried adding a filter for sla.breached == true in the webhook settings, but that didn’t change the payload structure.
Is there a specific query parameter I need to pass in the webhook URL to expand the metrics? Or is this data only available via the polling API and not the event stream? I’ve checked the docs but they’re a bit light on the payload schema for this specific event.
The routing/queues/realtime/queueMetrics event is tricky. It often sends a truncated payload or misses specific SLA breach details depending on how the queue is configured for reporting. If you need reliable SLA data for alerts, you shouldn’t rely solely on the webhook’s built-in metric object. It’s better to fetch the live data yourself when the webhook fires.
Here is a pattern that works. Use the webhook to catch the event, then make a synchronous GET request to the metrics API to pull the exact numbers you need before formatting your Slack message.
import requests
import json
# Your webhook handler receives the initial event
def handle_webhook_event(event_data):
queue_id = event_data.get('queueId')
# Fetch current real-time metrics for the specific queue
# You need the 'routing:queue:read' scope on the API user
metrics_url = f"https://api.mypurecloud.com/api/v2/routing/queues/{queue_id}/metrics/realtime"
headers = {
"Authorization": f"Bearer {GENESYS_TOKEN}",
"Accept": "application/json",
"Content-Type": "application/json"
}
response = requests.get(metrics_url, headers=headers)
if response.status_code == 200:
metrics = response.json()
# Extract SLA specific fields
# Note: The structure depends on your queue's SLA definition (e.g., answer speed)
sla_status = metrics.get('answerSpeed', {}).get('slaStatus', 'unknown')
current_level = metrics.get('answerSpeed', {}).get('currentLevel', 0)
# Now you have the actual numbers to send to Slack
slack_payload = {
"text": f"Queue {queue_id} SLA Status: {sla_status} (Current: {current_level}%)",
"channel": "#alerts"
}
# Send to Slack
send_slack(slack_payload)
The key is the answerSpeed object in the response. That contains the slaStatus which tells you if it’s breached. The webhook event itself might just tell you “something changed” but not what the current SLA percentage is. Fetching it directly ensures your alert is accurate.
Also check your OAuth token permissions. The API user calling the metrics endpoint must have routing:queue:read. If you see a 403, that’s the reason.