Python SDK PostUsersAsync throwing 400 on bulk user creation

Trying to script a bulk user import from CSV using the Python SDK. The docs say I should use PostUsersAsync but I’m getting a 400 Bad Request when I pass a list of UserCreateRequest objects.

Here is the snippet:

requests = []
for row in csv_rows:
 req = UserCreateRequest(
 email=row['email'],
 name=row['name'],
 external_id=row['id']
 )
 requests.append(req)

response = api.post_users_async(body=requests)

The error payload says Invalid input: body must be a single UserCreateRequest object, not an array. But the Swagger spec for /api/v2/users clearly shows the POST endpoint accepts a list in the body description: “Creates one or more users”.

Is the SDK just outdated or am I missing a wrapper? I tried sending a single object and it worked fine, but that defeats the purpose of bulk creation. The documentation quotes: “Use this method to create multiple users in a single API call.”

What am I missing here?

Cause:
The PostUsersAsync endpoint in the Genesys Cloud API expects a specific JSON structure for the body, not just a raw list of UserCreateRequest objects. When using the Python SDK, you often need to wrap the list of users in a specific container object or ensure the serialization matches the API’s expected schema for bulk operations. A common issue is passing the list directly without the wrapper or having mismatched field types in the UserCreateRequest.

Solution:
You need to ensure you are using the correct API client method and that the body is structured correctly. The post_users_async method typically requires a UserBulkCreateRequest object or similar wrapper depending on the SDK version. Check your SDK documentation for the exact wrapper. Here is a corrected approach using the standard PureCloudPlatformClientV2 pattern:

from platformclientv2 import ApiClient, RoutingApi, UserCreateRequest, UserBulkCreateRequest

# Initialize API client
api_client = ApiClient()
routing_api = RoutingApi(api_client)

users_to_create = []
for row in csv_rows:
 # Ensure all required fields are present
 user_req = UserCreateRequest(
 email=row['email'],
 name=row['name'],
 external_id=row['id'],
 # Add other required fields like division_id if needed
 division_id="your_division_id" 
 )
 users_to_create.append(user_req)

# Wrap the list in the bulk request object
bulk_request = UserBulkCreateRequest(body=users_to_create)

try:
 # Call the async bulk create endpoint
 response = routing_api.post_users_async(body=bulk_request)
 print(f"Job ID: {response.id}")
except Exception as e:
 print(f"Error: {e}")

Make sure you have the correct OAuth scopes. You need user:write and routing:write for this operation. Also, check the response payload for specific validation errors if it still fails. The 400 error usually contains a detailed message about which field is invalid.