I’ve got a script running to bulk-create users from a CSV file using the Genesys Cloud Python SDK. The goal is straightforward: read the CSV, construct the user object, and push it via the create_user method in a loop.
The script works for the first few rows, but then it starts throwing a 400 Bad Request error. The error message from the SDK is pretty vague, just saying “Validation failed” without pointing to the specific field. I’ve been staring at the CSV and the code for an hour now and can’t spot the issue.
Here’s the relevant part of the loop:
from gen_cloud_sdk_python.models import CreateUserRequest
from gen_cloud_sdk_python.client import ApiClient
# ... auth setup omitted ...
with open('new_users.csv', 'r') as f:
reader = csv.DictReader(f)
for row in reader:
try:
user_request = CreateUserRequest(
name=row['Name'],
email=row['Email'],
division_id=division_id,
roles=roles,
user_type="agent"
)
response = api_instance.create_user(body=user_request)
print(f"Created user: {row['Name']}")
except Exception as e:
print(f"Failed to create user {row['Name']}: {e}")
The CSV looks like this:
Name,Email,Role
John Doe,john.doe@example.com,agent
Jane Smith,jane.smith@example.com,agent
I’ve checked the email addresses in the CSV and they all look valid. I’m also using the correct division_id which I fetched earlier in the script. The roles list is populated with the correct role IDs for the “agent” role.
Is there something I’m missing in the CreateUserRequest object? Maybe a required field that’s not obvious? Or is the SDK version I’m using (v132) having issues with the user_type field? I’ve tried removing user_type and it still fails with the same 400 error.
Any help would be appreciated. I’m stuck.