Create User
Create a new user account. An activation email will be sent to the user.
This endpoint requires ROLE_ADMIN permissions.
Request Body
Unique username (lowercase recommended)
Array of role names to assign (e.g., ["ROLE_USER"])
Whether the user account is immediately activated
User’s language preference
URL to user’s profile image
Response
curl -X POST https://your-utmstack-instance.com/api/users \
-H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9..." \
-H "Content-Type: application/json" \
-d '{
"login": "jdoe",
"email": "[email protected]",
"firstName": "John",
"lastName": "Doe",
"authorities": ["ROLE_USER"],
"activated": true,
"langKey": "en"
}'
{
"id": 5,
"login": "jdoe",
"firstName": "John",
"lastName": "Doe",
"email": "[email protected]",
"activated": true,
"langKey": "en",
"createdBy": "admin",
"createdDate": "2024-01-15T10:30:00Z",
"authorities": ["ROLE_USER"],
"imageUrl": null
}
User Creation Flow
- Validate Input: Ensure login and email are unique
- Create User: User account is created in the database
- Send Email: Activation email is sent to the user’s email address
- Return User: Created user object is returned
Activation Email
When a user is created, an activation email is automatically sent containing:
- Welcome message
- Temporary password or activation link
- Instructions to complete account setup
Creating Admin Users
curl -X POST https://your-utmstack-instance.com/api/users \
-H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9..." \
-H "Content-Type: application/json" \
-d '{
"login": "admin2",
"email": "[email protected]",
"firstName": "Second",
"lastName": "Admin",
"authorities": ["ROLE_ADMIN"],
"activated": true,
"langKey": "en"
}'
Creating Multiple Users
import requests
def create_users_batch(api_url, token, users_data):
"""
Create multiple users from a list.
"""
url = f"{api_url}/users"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
created = []
errors = []
for user_data in users_data:
try:
response = requests.post(url, headers=headers, json=user_data)
if response.status_code == 201:
created.append(response.json())
print(f"✓ Created user: {user_data['login']}")
else:
errors.append({
"user": user_data['login'],
"error": response.json()
})
print(f"✗ Failed to create user: {user_data['login']}")
except Exception as e:
errors.append({
"user": user_data['login'],
"error": str(e)
})
return created, errors
# Example usage
users = [
{
"login": "analyst1",
"email": "[email protected]",
"firstName": "Alice",
"lastName": "Analyst",
"authorities": ["ROLE_USER", "ROLE_ANALYST"],
"activated": True,
"langKey": "en"
},
{
"login": "analyst2",
"email": "[email protected]",
"firstName": "Bob",
"lastName": "Analyst",
"authorities": ["ROLE_USER", "ROLE_ANALYST"],
"activated": True,
"langKey": "en"
}
]
api_url = "https://your-utmstack-instance.com/api"
token = "YOUR_TOKEN"
created, errors = create_users_batch(api_url, token, users)
print(f"\nCreated: {len(created)}, Errors: {len(errors)}")
Validation Rules
Login
- Must be unique
- Typically lowercase
- No special characters (alphanumeric and underscore recommended)
Email
- Must be unique
- Must be valid email format
- Case-insensitive comparison
Authorities
- Must include at least one role
- Roles must exist in the system
- Use
ROLE_ prefix for all roles
Best Practices
- Use Meaningful Logins: Use email prefix or full name as login
- Assign Minimal Roles: Start with
ROLE_USER, add more as needed
- Verify Email: Ensure email addresses are valid and accessible
- Set Language: Match user’s preferred language
- Batch Creation: For multiple users, implement error handling