I’ve got a Python script running via Airflow that pulls conversation metrics from Genesys Cloud using the genesyscloud SDK (v2.18.0). The goal is to dump the last 24 hours of data into an S3 bucket every morning.
The issue is the api_client.get_conversations_analytics_conversations_summary endpoint. It’s choking on the volume. I’m using the standard pagination loop, but I keep hitting 429 Too Many Requests before the job finishes. The SDK doesn’t seem to have built-in retry logic that plays nice with my specific timeout settings.
Here’s the loop:
from genesyscloud import analytics_api
api_instance = analytics_api.AnalyticsApi(api_client)
params = {
'interval': 'PT1H',
'date_from': '2023-10-25T00:00:00.000Z',
'date_to': '2023-10-26T00:00:00.000Z',
'group_by': 'routing.queue.id'
}
all_data = []
try:
response = api_instance.get_conversations_analytics_conversations_summary(**params)
all_data.extend(response.entities)
while response.next_page:
print(f"Fetching page: {response.next_page}")
response = api_instance.get_conversations_analytics_conversations_summary(
**params,
page_token=response.next_page
)
all_data.extend(response.entities)
except Exception as e:
print(f"Error: {e}")
When the 429 hits, the script just crashes. I’ve tried wrapping the request in a simple time.sleep(5) retry, but it feels hacky. Is there a cleaner way to handle this with the Python SDK? I don’t want to reinvent the wheel if there’s a retries config I’m missing in the ApiClient initialization. Also, writing all_data directly to S3 using boto3 is fine, but the memory usage spikes if the dataset is huge. Should I be chunking the writes or just letting it buffer?
The error trace usually ends with genesyscloud.rest.ApiException: (429) Reason: Too Many Requests. Any pointers?