I’m writing a script to bulk-create users from a CSV file using the Genesys Cloud Python Platform SDK. The goal is to provision a batch of agents and capture their IDs for a subsequent New Relic integration. I’m iterating through the CSV rows and calling users_api.post_users() for each entry. The first few users create successfully with a 201 status. After about ten calls, the script starts throwing 429 Too Many Requests errors. I’ve added a time.sleep(1) between requests, but the rate limit seems to trigger anyway. I’m using the genesyscloud package version 2.0.0.
Here is the relevant snippet:
from genesyscloud.platform.client import Client
import csv
def create_user(client, name, email):
user_body = {
"name": name,
"email": email,
"phone_numbers": []
}
response = client.users.post_users(body=user_body)
return response.body
with open('agents.csv') as f:
reader = csv.DictReader(f)
for row in reader:
try:
create_user(client, row['name'], row['email'])
except Exception as e:
print(f"Failed: {e}")
time.sleep(1)
The error message is 429 Too Many Requests. Retry after 60 seconds. I need a reliable way to handle the rate limiting without pausing the entire script for a minute. Is there a built-in retry mechanism in the SDK or a better pattern for this?