I have a CSV file with about 500 new agents that need to be provisioned in Genesys Cloud. I’m trying to write a Python script using the genesyscloud SDK to bulk-create these users.
The script works fine for the first 10-15 users. Then it starts throwing rate limit errors. I thought I could just add a time.sleep(1) between each create_user call, but it still fails eventually. Sometimes it gives me a 429 Too Many Requests, other times a 503 Service Unavailable.
Here is the loop I’m using:
from genesyscloud import PlatformClientBuilder
from genesyscloud import UserApi
import csv
import time
client = PlatformClientBuilder().build(client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
user_api = UserApi(client)
with open('new_agents.csv', 'r') as f:
reader = csv.DictReader(f)
for row in reader:
try:
body = {
'name': f"{row['firstName']} {row['lastName']}",
'email': row['email'],
'username': row['email'],
'division_id': DEFAULT_DIVISION_ID,
'roles': [DEFAULT_ROLE_ID]
}
user_api.post_users(body=body)
print(f"Created {row['firstName']}")
except Exception as e:
print(f"Failed {row['firstName']}: {e}")
time.sleep(1)
I noticed the SDK has a UserApi class but I don’t see a specific bulk endpoint method like post_users_bulk. Is there a better way to handle this? Or am I missing a header or parameter to increase the rate limit? The documentation isn’t very clear on bulk operations for users specifically.
Also, if I get a 429, how do I parse the Retry-After header from the SDK exception object? It just prints a generic error message.