Hey folks,
I’ve been working on a Python script to bulk-create users from a CSV file using the Genesys Cloud Platform SDK. The goal is to automate onboarding for our WFM team since manually adding agents in the UI is tedious.
Here is the relevant snippet:
from genesyscloud import PlatformClient, IdentityClient
from genesyscloud.resources import Users
client = PlatformClient()
client.login("client_id", "secret")
with open('agents.csv', 'r') as f:
for row in reader(f):
body = {
'name': row['name'],
'email': row['email'],
'addresses': [{'address': row['phone'], 'type': 'work'}],
'roles': [{'id': 'agent_role_id'}]
}
response, status = client.users.post_users(body=body)
if status != 201:
print(f"Failed: {response}")
The script runs but returns a 400 Bad Request error for every user. The error message says “Invalid email format” even though the emails in the CSV are valid.
I have tried:
- Validating the CSV data manually
- Using the Identity API instead of Users API
- Adding a delay between requests
- Checking the SDK documentation for required fields
The code works for single user creation when I hardcode the values, but fails with the CSV loop. The error log shows:
400: {"message": "Invalid email format", "code": "invalid.parameter"}
I’m not sure if the SDK is stripping special characters or if there is a threading issue. The script is single-threaded so that shouldn’t be the case.
Any ideas on how to debug this? The environment is Python 3.9 with genesyscloud-sdk 3.0.0. Running on US/Central time zone. The CSV has standard columns: name, email, phone, role_id.
The role_id is correct and exists in the tenant. I’ve verified the API token has the right scopes.
I’m stuck on this. The error doesn’t give more details. Is there a way to get verbose error output from the SDK? Or is there a specific format for the email field in the post_users call that I’m missing?
Thanks for any help.