Skip to main content
DELETE
/
usuarios
/
borrar
/
{user_id}
Delete User
curl --request DELETE \
  --url https://api.example.com/usuarios/borrar/{user_id}
{
  "message": "Usuario eliminado",
  "usuario": {
    "id": "507f1f77bcf86cd799439011",
    "nombre": "Juan Pérez",
    "email": "[email protected]",
    "rol": "visitante",
    "favoritos": ["507f191e810c19729de860ea"],
    "pois_visitados": ["507f191e810c19729de860ea"],
    "rutas_recorridas": [],
    "fecha_creacion": "2024-01-10T08:00:00Z"
  }
}

Authentication

This endpoint requires admin authentication. Include a valid JWT token with admin role in the Authorization header.
Authorization: Bearer <admin_jwt_token>

Path Parameters

user_id
string
required
The unique identifier of the user to delete (MongoDB ObjectId)

Response

message
string
Deletion confirmation message
usuario
object
Deleted user information
{
  "message": "Usuario eliminado",
  "usuario": {
    "id": "507f1f77bcf86cd799439011",
    "nombre": "Juan Pérez",
    "email": "[email protected]",
    "rol": "visitante",
    "favoritos": ["507f191e810c19729de860ea"],
    "pois_visitados": ["507f191e810c19729de860ea"],
    "rutas_recorridas": [],
    "fecha_creacion": "2024-01-10T08:00:00Z"
  }
}

Code Examples

curl -X DELETE "https://api.tesisrutas.com/usuarios/borrar/507f1f77bcf86cd799439011" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Error Responses

404
error
Not Found - User does not exist or was already deleted
{
  "detail": "El usuario no existe o ya fue eliminado."
}
403
error
Forbidden - User does not have admin privileges
{
  "detail": "No tienes permisos de administrador"
}
401
error
Unauthorized - Missing or invalid JWT token
{
  "detail": "Not authenticated"
}

Important Notes

This operation is permanent and cannot be undone. All user data including favorites, visited POIs, and route history will be permanently deleted from the database.
The response includes the complete user object before deletion, allowing you to archive or log the deleted user’s information if needed.

Implementation Details

Source: src/infrastructure/api/routers/usuario_router.py:104-114 This endpoint uses the EliminarUsuario use case which:
  • Validates the user exists before deletion
  • Uses MongoDB’s find_one_and_delete to atomically retrieve and delete the user
  • Returns the complete user object for logging/auditing purposes
  • Raises a ValueError if the user is not found

Build docs developers (and LLMs) love