Problem
Reading the CSV and calling client.users.post_users() for each line, but the loop crashes on the second row with a 400 Bad Request.
payload = {"name": row["name"], "email": row["email"], "division_id": "default"}
client.users.post_users(user_body=payload)
The error JSON says "reason": "invalid.division" even though we’ve checked the tenant IDs. Checked the SDK docs for batch imports and the endpoint list doesn’t show a clear path for CSV uploads.
Are you reusing the same client instance across the loop or instantiating it fresh each time? Also, is that division_id actually valid for the org? The error got cut off, but invalid.divisio usually means the ID doesn’t exist or the token lacks scope.
Here’s a safer way to handle this in Python. You’ll want to validate the division first and handle exceptions so one bad row doesn’t kill the whole batch.
from purecloudplatformclientv2 import ApiClient, Configuration, UsersApi
import csv
# Setup client once
configuration = Configuration()
configuration.access_token = "YOUR_OAUTH_TOKEN"
api_client = ApiClient(configuration)
users_api = UsersApi(api_client)
with open('users.csv', mode='r') as file:
reader = csv.DictReader(file)
for row in reader:
try:
payload = {
"name": row["name"],
"email": row["email"],
"division_id": row.get("division_id", "default") # Check if this is actually valid
}
# Post the user
users_api.post_users(user_body=payload)
print(f"Created user: {row['name']}")
except Exception as e:
# Log the error but keep going
print(f"Failed to create {row['name']}: {e}")
If the division ID is truly default, make sure you’re not hitting a rate limit. Genesys throttles hard on user creation. Add a small sleep if you’re seeing 429s too.