Skip to main content

POST /api/users//roles/

Assigns a role to a user, granting them the associated permissions. This endpoint requires write privileges or admin role.

Authentication

This endpoint requires JWT authentication with one of the following:
  • WRITE_PRIVILEGES authority
  • ADMIN role

Path Parameters

id
UUID
required
The unique identifier of the user
roleId
UUID
required
The unique identifier of the role to assign

Response

This endpoint returns no content on success (HTTP 204).

Error Codes

  • 204 - Role assigned successfully (no content returned)
  • 401 - Unauthorized: Missing or invalid JWT token
  • 403 - Forbidden: Insufficient permissions
  • 404 - Not Found: User or role does not exist

Example Request

curl -X POST https://api.example.com/api/users/550e8400-e29b-41d4-a716-446655440000/roles/660e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Example Success Response

HTTP/1.1 204 No Content

Example Error Response

{
  "timestamp": "2026-03-04T10:30:00Z",
  "requestId": "abc123-def456",
  "message": "Role not found",
  "detail": "Rol con id 660e8400-e29b-41d4-a716-446655440000 no encontrado"
}

Notes

  • A user can have multiple roles assigned
  • Assigning a role grants the user all permissions associated with that role
  • If the user already has the role assigned, the operation will succeed without changes
  • This action is logged in the audit log with module “USUARIOS” and action “ASIGNAR_ROL”

Example: Assigning Multiple Roles

To assign multiple roles to a user, call the endpoint multiple times:
# Assign USER role
curl -X POST https://api.example.com/api/users/550e8400-e29b-41d4-a716-446655440000/roles/660e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

# Assign MANAGER role
curl -X POST https://api.example.com/api/users/550e8400-e29b-41d4-a716-446655440000/roles/770e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Build docs developers (and LLMs) love