Python SDK bulk user creation failing with 400 on email uniqueness check

How do I handle the email uniqueness validation when bulk creating users via the Python SDK?

I’m writing a script to ingest a CSV of new agents. The logic reads the CSV, builds a list of User objects, and then calls platform_client.users.create_user(user) in a loop. It works for the first user. The second one always fails with a 400 Bad Request.

Here’s the relevant snippet:

from nice_cxone_platform_sdk.client import create_client
from nice_cxone_platform_sdk.models import User
import csv

client = create_client()
users_api = client.users

with open('agents.csv', 'r') as f:
 reader = csv.DictReader(f)
 for row in reader:
 user = User(
 name=row['name'],
 email=row['email'],
 username=row['username']
 )
 try:
 users_api.create_user(user)
 print(f"Created {user.name}")
 except Exception as e:
 print(f"Failed {user.name}: {e}")

The error message is Email address is already in use. This is weird because the emails in the CSV are unique. I checked the CXone admin console. The users don’t exist there.

Is the SDK caching the last created user’s email? Or am I missing a step to clear the session state between calls? I tried adding a time.sleep(1) but that didn’t help. The username field is also unique.

The only thing I can think of is that the username defaults to the email if not explicitly set in the model constructor, but I am setting it.

Here is the JSON payload for the second call that fails:

{
 "name": "Jane Doe",
 "email": "jane.doe@company.com",
 "username": "jdoe",
 "divisionId": "12345"
}

The first call uses john.doe@company.com.

Why is it complaining about an existing email?