Skip to main content

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:
id_usuario
integer
required
Auto-generated primary key for the user
rol_usuario
integer
required
Foreign key reference to RolUsuario (user role)
email
string
required
User’s email address (max 50 characters)
placa
string
Vehicle license plate number (max 8 characters, optional)
contrasena
string
required
User password (automatically hashed using SHA-256, max 64 characters)
token_notificacion
string
required
Firebase Cloud Messaging token for push notifications
fecha_creacion
date
Auto-generated creation date
fecha_modificacion
date
Auto-updated modification date
id_ciudad
integer
required
Foreign key reference to Ciudad (city), defaults to 1
id_pais
integer
required
Foreign key reference to Pais (country), defaults to 1
estado
integer
required
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:
id
integer
required
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:
rol_usuario
integer
required
User role ID (foreign key to RolUsuario)
email
string
required
User’s email address (max 50 characters)
placa
string
Vehicle license plate (max 8 characters, optional)
contrasena
string
required
Plain text password (will be automatically hashed using SHA-256)
token_notificacion
string
required
Firebase Cloud Messaging token
id_ciudad
integer
City ID (defaults to 1)
id_pais
integer
Country ID (defaults to 1)
estado
integer
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:
id
integer
required
The unique identifier of the user to update
Request Body Parameters:
rol_usuario
integer
required
User role ID
email
string
required
User’s email address
placa
string
Vehicle license plate (optional)
contrasena
string
required
User password (if updating, provide the hashed value)
token_notificacion
string
required
Firebase Cloud Messaging token
id_ciudad
integer
required
City ID
id_pais
integer
required
Country ID
estado
integer
required
User status
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:
id
integer
required
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:
id
integer
required
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:
HTTP 204 No Content
  • 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)

Build docs developers (and LLMs) love