Python SDK bulk user creation: 400 Bad Request on department_id mismatch

Hey everyone.

I’m writing a script to bulk-create users from a CSV file using the genesyscloud Python SDK. The goal is to spin up temporary agents for a peak season project. I have the OAuth token generation working fine, but the create_user call is failing with a 400 error for about half the records.

Here is the core loop:

from genesyscloud.platform_sdk.client import PlatformClient
from genesyscloud.users.models import CreateUserRequest

client = PlatformClient(...)
users_api = client.users

def create_user_from_row(row):
 body = CreateUserRequest(
 email=row['email'],
 name=row['name'],
 username=row['username'],
 division_id=row['division_id'],
 department_id=row['department_id'] # This is the suspect
 )
 
 try:
 result = users_api.post_users(body=body)
 print(f"Created {row['username']}")
 except Exception as e:
 print(f"Failed {row['username']}: {e.status_code} {e.reason}")
 print(e.body) # Prints the detailed error

The error response looks like this:

{
 "errors": [
 {
 "code": "validationError",
 "message": "Invalid departmentId: 'd-12345'. Department must belong to the same division as the user."
 }
 ]
}

I know the department exists. I can query it via the API and get a 200 OK. The issue seems to be that the department ID in my CSV belongs to a different division than the division_id I’m passing in the CreateUserRequest. The SDK doesn’t validate this before sending the request, which is annoying.

I need to fetch the correct department ID for each user’s division before creating the user. Is there a way to do this efficiently without making an extra API call per user? Maybe cache the division-to-department mapping? Or is there a better way to structure the CreateUserRequest to auto-resolve the department?

Also, the SDK version is 2.0.18. I’m running this on a local machine, not in a serverless environment, so rate limiting isn’t my main concern yet, but efficiency is. I don’t want to wait 20 minutes for 500 users if I can help it.