Skip to main content

POST /usuario/crear

Creates a new user with complete profile information and assigns a role.

Request

nombres
string
required
User’s first name(s)
apellidoPaterno
string
required
User’s paternal last name
apellidoMaterno
string
required
User’s maternal last name
dni
string
required
User’s national identification number (DNI)
direccion
string
required
User’s physical address
telefono
string
required
User’s phone number
estado
boolean
required
User’s active status (true = active, false = inactive)
userName
string
required
Username for authentication
password
string
required
User’s password (will be encrypted)
rolId
number
required
ID of the role to assign to this user

Request Example

curl -X POST https://api.example.com/usuario/crear \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{
    "nombres": "Juan",
    "apellidoPaterno": "García",
    "apellidoMaterno": "López",
    "dni": "12345678",
    "direccion": "Av. Principal 123, Lima",
    "telefono": "+51987654321",
    "estado": true,
    "userName": "jgarcia",
    "password": "securepass123",
    "rolId": 2
  }'

Response

id
number
Unique identifier for the created user
nombres
string
User’s first name(s)
apellidoPaterno
string
User’s paternal last name
apellidoMaterno
string
User’s maternal last name
dni
string
User’s DNI
direccion
string
User’s address
telefono
string
User’s phone number
estado
boolean
User’s active status
authUser
object
Associated authentication user account
id
integer
Auth user ID
userName
string
Username
password
string
Encrypted password hash

Response Example

{
  "id": 15,
  "nombres": "Juan",
  "apellidoPaterno": "García",
  "apellidoMaterno": "López",
  "dni": "12345678",
  "direccion": "Av. Principal 123, Lima",
  "telefono": "+51987654321",
  "estado": true,
  "authUser": {
    "id": 20,
    "userName": "jgarcia",
    "password": "$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy"
  }
}

Status Codes

  • 200 OK - User created successfully
  • 400 Bad Request - Username already exists or validation failed

POST /usuario/asignar-rol

Assigns a role to an existing user.

Request

usuarioId
number
required
ID of the user to assign the role to
rolId
number
required
ID of the role to assign

Request Example

curl -X POST https://api.example.com/usuario/asignar-rol \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{
    "usuarioId": 15,
    "rolId": 2
  }'

Response

"Rol asignado con éxito"

Status Codes

  • 200 OK - Role assigned successfully

PUT /usuario/

Updates an existing user’s information.

Path Parameters

id
number
required
ID of the user to update

Request Body

nombres
string
User’s first name(s)
apellidoPaterno
string
User’s paternal last name
apellidoMaterno
string
User’s maternal last name
dni
string
User’s DNI
direccion
string
User’s address
telefono
string
User’s phone number
estado
boolean
User’s active status
userName
string
Username
password
string
New password (optional, only if changing password)
rolId
number
Role ID to assign

Request Example

curl -X PUT https://api.example.com/usuario/15 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{
    "nombres": "Juan Carlos",
    "apellidoPaterno": "García",
    "apellidoMaterno": "López",
    "dni": "12345678",
    "direccion": "Av. Principal 456, Lima",
    "telefono": "+51987654321",
    "estado": true,
    "userName": "jgarcia",
    "rolId": 2
  }'

Response

Returns the updated user object (same structure as create response).

Status Codes

  • 200 OK - User updated successfully
  • 404 Not Found - User not found

PUT /usuario//estado

Changes a user’s active/inactive status.

Path Parameters

id
number
required
ID of the user

Query Parameters

estado
boolean
required
New status (true = active, false = inactive)

Request Example

curl -X PUT "https://api.example.com/usuario/15/estado?estado=false" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response

Empty response body on success.

Status Codes

  • 200 OK - Status updated successfully
  • 404 Not Found - User not found

GET /usuario/estado

Lists all users filtered by their active status, including their assigned role.

Query Parameters

estado
boolean
required
Filter by status (true = active users, false = inactive users)

Request Example

curl -X GET "https://api.example.com/usuario/estado?estado=true" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response

Returns an array of users with their role information.
usuarios
array
List of users matching the status filter
id
number
User ID
nombres
string
User’s first name(s)
apellidoPaterno
string
Paternal last name
apellidoMaterno
string
Maternal last name
dni
string
DNI
direccion
string
Address
telefono
string
Phone number
estado
boolean
Active status
userName
string
Username
rol
string
Role name (e.g., “ADMIN”, “USER”, “ALMACENERO”)

Response Example

[
  {
    "id": 15,
    "nombres": "Juan",
    "apellidoPaterno": "García",
    "apellidoMaterno": "López",
    "dni": "12345678",
    "direccion": "Av. Principal 123, Lima",
    "telefono": "+51987654321",
    "estado": true,
    "userName": "jgarcia",
    "rol": "ADMIN"
  },
  {
    "id": 16,
    "nombres": "María",
    "apellidoPaterno": "Rodríguez",
    "apellidoMaterno": "Pérez",
    "dni": "87654321",
    "direccion": "Jr. Comercio 456, Lima",
    "telefono": "+51912345678",
    "estado": true,
    "userName": "mrodriguez",
    "rol": "USER"
  }
]

Status Codes

  • 200 OK - Users retrieved successfully

Build docs developers (and LLMs) love