Python SDK post_users throws 400 on CSV bulk create

Problem

We’re trying to automate user onboarding using the Python SDK and a CSV file. The script loops through the rows. It calls post_users for each line. First five records go through without issue. Then the client throws a 400 Bad Request. Error body points to a validation failure on external_id. We verified the CSV format matches the docs. The endpoint is /api/v2/users. Logs show nothing useful. No stack trace either.

for row in csv_reader:
 body = { "first_name": row[0], "external_id": row[2] }
 api_response = post_users(body=body)

The 400 isn’t a rate limit issue. It’s the external_id uniqueness constraint. You’re likely hitting a duplicate in the CSV after row five. Add a try-except block to catch ApiException. Check the error message for the specific conflict. Also, verify your external_id format matches the regex ^[a-zA-Z0-9_-]+$.

try:
 api_instance.post_users(body=user_body)
except ApiClient.ApiException as e:
 print(f"Failed on row {i}: {e.body}")

Double-check your CSV for duplicates.