Skip to main content

Create User

Create a new user account. An activation email will be sent to the user.
This endpoint requires ROLE_ADMIN permissions.

Request Body

login
string
required
Unique username (lowercase recommended)
email
string
required
Unique email address
firstName
string
required
User’s first name
lastName
string
required
User’s last name
authorities
array
required
Array of role names to assign (e.g., ["ROLE_USER"])
activated
boolean
default:"true"
Whether the user account is immediately activated
langKey
string
default:"en"
User’s language preference
imageUrl
string
URL to user’s profile image

Response

id
integer
Generated user ID
login
string
Username
email
string
Email address
firstName
string
First name
lastName
string
Last name
activated
boolean
Activation status
authorities
array
Assigned roles
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

  1. Validate Input: Ensure login and email are unique
  2. Create User: User account is created in the database
  3. Send Email: Activation email is sent to the user’s email address
  4. 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
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

Python
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

  1. Use Meaningful Logins: Use email prefix or full name as login
  2. Assign Minimal Roles: Start with ROLE_USER, add more as needed
  3. Verify Email: Ensure email addresses are valid and accessible
  4. Set Language: Match user’s preferred language
  5. Batch Creation: For multiple users, implement error handling

Build docs developers (and LLMs) love