Skip to main content

Update User

Update an existing user account.
This endpoint requires ROLE_ADMIN permissions.

Request Body

id
integer
required
User ID to update
login
string
required
Username (must match existing or be unique)
email
string
required
Email address (must match existing or be unique)
firstName
string
required
User’s first name
lastName
string
required
User’s last name
authorities
array
required
Array of role names
activated
boolean
required
Whether the account is activated
langKey
string
Language preference
imageUrl
string
Profile image URL

Response

id
integer
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 PUT https://your-utmstack-instance.com/api/users \
  -H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "id": 5,
    "login": "jdoe",
    "email": "[email protected]",
    "firstName": "John",
    "lastName": "Doe",
    "authorities": ["ROLE_USER", "ROLE_ANALYST"],
    "activated": true,
    "langKey": "en"
  }'
{
  "id": 5,
  "login": "jdoe",
  "firstName": "John",
  "lastName": "Doe",
  "email": "[email protected]",
  "activated": true,
  "langKey": "en",
  "authorities": ["ROLE_USER", "ROLE_ANALYST"],
  "imageUrl": null
}

Update Current User Account

Update the currently authenticated user’s own account information.
Users can only update their own account through this endpoint. Roles cannot be changed.

Request Body

firstName
string
required
First name
lastName
string
required
Last name
email
string
required
Email address
langKey
string
Language preference
imageUrl
string
Profile image URL
curl -X POST https://your-utmstack-instance.com/api/account \
  -H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "firstName": "Jane",
    "lastName": "Doe",
    "email": "[email protected]",
    "langKey": "en"
  }'

Change Password

Change the current user’s password.

Request Body

currentPassword
string
required
Current password
newPassword
string
required
New password (4-100 characters)
curl -X POST https://your-utmstack-instance.com/api/account/change-password \
  -H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "currentPassword": "old-password",
    "newPassword": "new-secure-password-123"
  }'

Validation Rules

Email Uniqueness

Email addresses must be unique across all users. The check is case-insensitive.

Login Uniqueness

Usernames must be unique. The check is case-sensitive.

Admin Protection

The system prevents removing ROLE_ADMIN from the last remaining admin user.

Password Requirements

  • Minimum length: 4 characters
  • Maximum length: 100 characters

Update Examples

Add Analyst Role

Python
import requests

def add_analyst_role(api_url, token, user_id):
    # Get current user
    headers = {"Authorization": f"Bearer {token}"}
    response = requests.get(f"{api_url}/users/{user_id}", headers=headers)
    user = response.json()
    
    # Add ROLE_ANALYST if not present
    if "ROLE_ANALYST" not in user["authorities"]:
        user["authorities"].append("ROLE_ANALYST")
        
        # Update user
        headers["Content-Type"] = "application/json"
        response = requests.put(f"{api_url}/users", headers=headers, json=user)
        
        if response.status_code == 200:
            print(f"Added ROLE_ANALYST to user {user['login']}")
        else:
            print(f"Failed to update user: {response.text}")

Deactivate User

Python
import requests

def deactivate_user(api_url, token, user_id):
    headers = {
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/json"
    }
    
    # Get user
    response = requests.get(f"{api_url}/users/{user_id}", headers=headers)
    user = response.json()
    
    # Set activated to false
    user["activated"] = False
    
    # Update
    response = requests.put(f"{api_url}/users", headers=headers, json=user)
    return response.status_code == 200

Best Practices

  1. Verify Before Update: Get current user data before updating
  2. Preserve Roles: Don’t accidentally remove important roles
  3. Admin Protection: Always maintain at least one admin user
  4. Email Validation: Ensure email addresses are valid before updating
  5. Audit Changes: Log all user modifications for compliance

Build docs developers (and LLMs) love