I’m trying to automate the onboarding of a batch of agents by reading a CSV and hitting the /api/v2/users endpoint using the Python SDK (genesyscloud package v2.8.10).
The logic is straightforward: read the row, check if the user exists, if not, create them. The issue is that the user_api.get_user_by_email call seems to be throttling or timing out when I run this in a loop for ~50 users, and even when it succeeds, the subsequent create call throws a 409 Conflict claiming the email is already in use, despite the check returning None.
Here’s the snippet I’m using for the creation logic:
from genesyscloud import PlatformClientConfiguration, UserApi
import csv
config = PlatformClientConfiguration(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
base_url="https://myorg.mygenesyscloud.com"
)
user_api = UserApi(config)
with open('new_agents.csv', 'r') as f:
reader = csv.DictReader(f)
for row in reader:
email = row['email']
# Check existence
try:
existing, resp = user_api.get_user_by_email(email=email, expand=['addresses'])
if resp.status_code == 200:
print(f"User {email} exists. Skipping.")
continue
except Exception as e:
if e.status == 404:
pass # User doesn't exist, proceed
else:
print(f"Error checking user: {e}")
continue
# Create user
user_body = {
"email": email,
"name": row['name'],
"email_addresses": [{
"email": email,
"type": "work"
}]
}
try:
created_user, resp = user_api.post_users(body=user_body)
print(f"Created user: {created_user.id}")
except Exception as e:
print(f"Failed to create {email}: {e.status} - {e.body}")
The error I’m getting is consistently a 409 with the body:
{
"message": "Conflict",
"errors": [
{
"code": "duplicate.email",
"message": "The email address is already in use."
}
]
}
I’ve added a time.sleep(1) between iterations to avoid rate limiting, but the conflict persists. Is there a better way to batch create users, or am I missing a specific header or parameter to handle the uniqueness check correctly? The post_users method doesn’t seem to have an ignore_if_exists flag.
Also, I noticed the SDK documentation mentions put_users for updates, but I don’t see a bulk endpoint like post_users_batch. Is that intentional or am I looking in the wrong API group?