Genesys Python SDK: Bulk user creation from CSV throwing 400 on divisionId

I’m trying to bulk-create users from a CSV file using the Genesys Cloud Platform SDK for Python. The script reads the CSV, constructs the CreateUserRequest object, and calls post_users_user(). It works fine for the first few users, but then I start getting 400 Bad Request errors. The error message says “divisionId is required”. I’m explicitly setting the divisionId in the request body, so I’m not sure what’s going on. Here’s the relevant code snippet:

from _platform_client import PlatformClientV2, CreateUserRequest
from _platform_client.configuration import Configuration

config = Configuration()
config.host = 'https://api.mypurecloud.com'
api_client = PlatformClientV2(configuration=config)

user_request = CreateUserRequest()
user_request.name = row['name']
user_request.email = row['email']
user_request.division_id = row['division_id'] # This is definitely in the CSV

try:
 api_response = api_client.user_management.post_users_user(body=user_request)
 print(f"Created user: {api_response.id}")
except Exception as e:
 print(f"Error creating user {row['name']}: {e}")

The division_id is a valid UUID that I’ve copied directly from the API response of an existing user. I’ve also tried passing it as a string, but that didn’t help. I’m running this on a local machine in Sydney, so latency shouldn’t be an issue. What am I missing here?

Try switching to put_users_bulk. The single post_users_user endpoint is strict about the divisionId format and often chokes if you’re passing a name instead of the actual ID string, or if the division isn’t fully pagated in the cache yet.

Here’s a quick snippet to fetch the division ID first, then batch create. It’s way more forgiving on the payload structure.

from genesyscloud import PlatformClient, PlatformClientBuilder
from genesyscloud.admin import AdminApi

client = PlatformClientBuilder().with_client_id_secret(CLIENT_ID, SECRET).build()
admin_api = AdminApi(client)

# Get the actual division ID. Don't guess it.
division_name = "My Division"
divisions, _ = admin_api.get_admin_divisions()
target_div = next((d for d in divisions.entities if d.name == division_name), None)

if not target_div:
 raise Exception(f"Division {division_name} not found")

# Prepare bulk payload
users_payload = []
for row in csv_data:
 users_payload.append({
 "name": row['name'],
 "email": row['email'],
 "division": {
 "id": target_div.id # Must be the ID, not the name
 },
 "roles": [
 {
 "id": "12345-67890-12345-67890" # Hardcode or lookup role ID
 }
 ]
 })

# Execute bulk create
try:
 response, status_code = admin_api.put_users_bulk(body=users_payload)
 print(f"Status: {status_code}")
except Exception as e:
 print(f"Failed: {e}")

The single create endpoint is finicky with division resolution. The bulk endpoint handles the references better. Also make sure you’re not hitting the 429 limit by adding a small sleep between batches if you’re doing thousands.