Working on a bulk user import script using the Genesys Cloud Python SDK. I have a CSV with about 200 employees and I’m trying to loop through the rows to create users via api_client.users_api.post_users(). The script runs fine for the first 10-15 users, then I start hitting 429 Too Many Requests errors consistently. I’ve tried adding time.sleep(1) between calls, but it seems fragile. Is there a better way to handle rate limiting in the Python SDK, or should I be batching these requests differently? Here’s the relevant chunk:
import pandas as pd
from genesyscloud import UsersApi, Configuration
# ... setup config and api_client ...
users_api = UsersApi(api_client)
df = pd.read_csv('employees.csv')
for index, row in df.iterrows():
try:
user_body = {
"name": row['Name'],
"email": row['Email'],
"username": row['Username']
}
users_api.post_users(body=user_body)
print(f"Created {row['Name']}")
except Exception as e:
print(f"Failed {row['Name']}: {e}")
time.sleep(5) # Hacky retry
The error payload looks like:
{"code":"too_many_requests","message":"Request was throttled"}
I don’t want to hardcode sleep intervals if there’s a more programmatic way to handle the Retry-After header in the response. Also, is there a specific endpoint for bulk creation that I’m missing, or is post_users the only game in town?