So we’re hitting rate limits on the /api/v2/analytics/conversations/details endpoint when pulling conversation data for a specific queue, which is… great. The thing is, the query is fairly simple - just conversationId, queueId, and wrapup codes, with a date range of the last 24 hours. I’m throttling requests to 15/sec, but it’s still happening intermittently, and the error isn’t consistent, sometimes it’s a 429 with a retry-after of 60s, other times it just fails completely. It’s making building dashboards that need real-time data a complete pain.
I’ve got the code here - it’s httpx, no SDK nonsense - and it’s working fine for other queues, so it’s definitely something queue specific. The queue has roughly 80 agents and an average call volume of around 200 conversations per hour. Here’s the pagination loop; it’s doing the right thing, I swear, but I’m starting to suspect the API just can’t handle the load even with the rate limiting. Seriously, the pagination limits on this thing are criminal. I’m starting to think we need to just cache everything aggressively. Anyway, the code:
import httpx
import json
import time
GENESYS_CLOUD_URL = "https://genesyscloud.com"
API_VERSION = "v2"
AUTH_TOKEN = "YOUR_AUTH_TOKEN" #obviously replace this
QUEUE_ID = "YOUR_QUEUE_ID"
CONVERSATION_START_TIME = "2024-01-01T00:00:00Z"
CONVERSATION_END_TIME = "2024-01-02T00:00:00Z"
headers = {
"Authorization": f"Bearer {AUTH_TOKEN}",
"Content-Type": "application/json"
}
def get_conversation_details(queue_id, start_time, end_time, page_size=100, page_number=1):
url = f"{GENESYS_CLOUD_URL}/api/{API_VERSION}/analytics/conversations/details"
params = {
"queueId": queue_id,
"startTime": start_time,
"endTime": end_time,
"pageSize": page_size,
"pageNumber": page_number,
"sortBy": "conversationId",
"sortOrder": "asc"
}
response = httpx.get(url, headers=headers, params=params)
response.raise_for_status()
return response.json()
total_conversations = 0
all_conversations = []
page_number = 1
while True:
try:
data = get_conversation_details(QUEUE_ID, CONVERSATION_START_TIME, CONVERSATION_END_TIME, page_number=page_number)
conversations = data.get("entities", [])
if not conversations:
break
all_conversations.extend(conversations)
total_conversations += len(conversations)
print(f"Processed page {page_number}, total conversations: {total_conversations}")
page_number += 1
time.sleep(0.066) #throttling to ~15 requests/sec
except httpx.HTTPStatusError as e:
print(f"Error fetching page {page_number}: {e}")
if e.response.status_code == 429:
retry_after = int(e.response.headers.get("Retry-After", 60))
print(f"Rate limited, retrying after {retry_after} seconds")
time.sleep(retry_after)
continue
else:
break
print(f"Successfully fetched {total_conversations} conversations.")
ship it