Overview
The Usuarios API provides endpoints for creating, reading, updating, and deleting users in the system. All user passwords are automatically hashed using SHA-256 encryption upon creation.
Base URL: /Database/Database/usuarios/
Usuario Model
The Usuario model represents a user in the system with the following fields:
Auto-generated primary key for the user
Foreign key reference to RolUsuario (user role)
User’s email address (max 50 characters)
Vehicle license plate number (max 8 characters, optional)
User password (automatically hashed using SHA-256, max 64 characters)
Firebase Cloud Messaging token for push notifications
Auto-generated creation date
Auto-updated modification date
Foreign key reference to Ciudad (city), defaults to 1
Foreign key reference to Pais (country), defaults to 1
User status: 0 (Inactive), 1 (Active), 3 (Disabled). Defaults to 0
Endpoints
List All Users
Retrieve a list of all users in the system.
GET /Database/Database/usuarios/
Example Request:
curl -X GET "http://your-domain.com/Database/Database/usuarios/" \
-H "Content-Type: application/json"
Example Response:
[
{
"id_usuario": 1,
"rol_usuario": 2,
"email": "[email protected]",
"placa": "ABC1234",
"contrasena": "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3",
"token_notificacion": "fcm_token_here",
"fecha_creacion": "2024-01-15",
"fecha_modificacion": "2024-01-15",
"id_ciudad": 1,
"id_pais": 1,
"estado": 1
}
]
Get Single User
Retrieve details of a specific user by ID.
GET /Database/Database/usuarios/{id}/
Path Parameters:
The unique identifier of the user
Example Request:
curl -X GET "http://your-domain.com/Database/Database/usuarios/1/" \
-H "Content-Type: application/json"
Example Response:
{
"id_usuario": 1,
"rol_usuario": 2,
"email": "[email protected]",
"placa": "ABC1234",
"contrasena": "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3",
"token_notificacion": "fcm_token_here",
"fecha_creacion": "2024-01-15",
"fecha_modificacion": "2024-01-15",
"id_ciudad": 1,
"id_pais": 1,
"estado": 1
}
Create User
Create a new user in the system.
POST /Database/Database/usuarios/
Request Body Parameters:
User role ID (foreign key to RolUsuario)
User’s email address (max 50 characters)
Vehicle license plate (max 8 characters, optional)
Plain text password (will be automatically hashed using SHA-256)
Firebase Cloud Messaging token
Country ID (defaults to 1)
User status: 0 (Inactive), 1 (Active), 3 (Disabled). Defaults to 0
Example Request:
curl -X POST "http://your-domain.com/Database/Database/usuarios/" \
-H "Content-Type: application/json" \
-d '{
"rol_usuario": 2,
"email": "[email protected]",
"placa": "XYZ5678",
"contrasena": "mypassword123",
"token_notificacion": "fcm_token_12345",
"id_ciudad": 1,
"id_pais": 1,
"estado": 1
}'
Example Response:
{
"id_usuario": 2,
"rol_usuario": 2,
"email": "[email protected]",
"placa": "XYZ5678",
"contrasena": "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3",
"token_notificacion": "fcm_token_12345",
"fecha_creacion": "2024-03-09",
"fecha_modificacion": "2024-03-09",
"id_ciudad": 1,
"id_pais": 1,
"estado": 1
}
Password Hashing: When creating a new user, the password (contrasena) is automatically hashed using SHA-256 encryption. The plain text password is never stored in the database. The hash is computed in the model’s save() method before the record is created.
Update User
Update an existing user’s information.
PUT /Database/Database/usuarios/{id}/
Path Parameters:
The unique identifier of the user to update
Request Body Parameters:
Vehicle license plate (optional)
User password (if updating, provide the hashed value)
Firebase Cloud Messaging token
Example Request:
curl -X PUT "http://your-domain.com/Database/Database/usuarios/1/" \
-H "Content-Type: application/json" \
-d '{
"rol_usuario": 2,
"email": "[email protected]",
"placa": "ABC1234",
"contrasena": "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3",
"token_notificacion": "fcm_token_updated",
"id_ciudad": 1,
"id_pais": 1,
"estado": 1
}'
Example Response:
{
"id_usuario": 1,
"rol_usuario": 2,
"email": "[email protected]",
"placa": "ABC1234",
"contrasena": "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3",
"token_notificacion": "fcm_token_updated",
"fecha_creacion": "2024-01-15",
"fecha_modificacion": "2024-03-09",
"id_ciudad": 1,
"id_pais": 1,
"estado": 1
}
Password Updates: The automatic SHA-256 hashing only occurs on user creation (when id_usuario is null). When updating an existing user, if you need to change the password, you must provide the pre-hashed SHA-256 value in the contrasena field.
Partial Update User
Partially update a user’s information (only specified fields).
PATCH /Database/Database/usuarios/{id}/
Path Parameters:
The unique identifier of the user to update
Example Request:
curl -X PATCH "http://your-domain.com/Database/Database/usuarios/1/" \
-H "Content-Type: application/json" \
-d '{
"estado": 3,
"email": "[email protected]"
}'
Delete User
Delete a user from the system.
DELETE /Database/Database/usuarios/{id}/
Path Parameters:
The unique identifier of the user to delete
Example Request:
curl -X DELETE "http://your-domain.com/Database/Database/usuarios/1/" \
-H "Content-Type: application/json"
Example Response:
- RolUsuarios API - Manage user roles
- Ciudades API - Manage cities
- Paises API - Manage countries
Notes
- All endpoints use standard REST conventions with JSON request/response bodies
- The API uses Django REST Framework’s ModelViewSet which provides full CRUD operations
- Passwords are automatically hashed with SHA-256 on creation only
- The
fecha_creacion field is automatically set on creation
- The
fecha_modificacion field is automatically updated on every save
- User status can be: 0 (Inactive), 1 (Active), or 3 (Disabled)