Overview
The Clients API manages customer records with support for SMS marketing campaigns via Twilio integration.Cliente Model (Client)
integer
Unique client identifier (auto-generated)
string
Client name (max 150 characters, required)
string
Phone number (max 20 characters, optional)
string
ID/document number (max 20 characters, optional)
boolean
Active status (default: true)
datetime
Creation timestamp (auto-generated)
integer
Foreign key to User who created the client (PROTECT constraint)
PlantillaSMS Model (SMS Template)
integer
Template identifier
string
Template name (max 100 characters)
text
Message template (use
{nombre} for personalization)boolean
Active status (default: true)
datetime
Creation timestamp
integer
Foreign key to User
CampanaSMS Model (SMS Campaign)
integer
Campaign identifier
string
Campaign name (max 200 characters)
text
Message content
integer
Total recipients (default: 0)
integer
Successfully sent count (default: 0)
integer
Failed send count (default: 0)
string
Campaign status:
pendiente, procesando, completado, or errordatetime
Creation timestamp
datetime
Completion timestamp (optional)
integer
Foreign key to User
SMSLog Model (SMS Log)
integer
Log entry identifier
integer
Foreign key to CampanaSMS
integer
Foreign key to Cliente
text
Message content sent
string
Send status:
enviado or fallidostring
Twilio message SID (max 100 characters, optional)
text
Error message if failed (optional)
datetime
Log timestamp
List Clients
Requires authentication. Returns clients owned by the authenticated user.
Response
Returns rendered HTML with list of active clients.Create Client
Request Parameters
string
required
Client name (max 150 characters)
string
Phone number (max 20 characters)
string
ID/document number (max 20 characters)
boolean
default:"true"
Active status
Response
Success (HTTP 302): Redirects to/clientes/ with flash message
Validation Error (HTTP 200): Re-renders form with errors
Create Client (AJAX)
Response
Update Client
URL Parameters
integer
required
Client ID to update
Response
Success: Redirects to clients list Not Found (HTTP 404): Client doesn’t exist or doesn’t belong to userDelete Client
URL Parameters
integer
required
Client ID to delete
Response
Success: Client deleted, redirects to list Protected Error: Cannot delete due to foreign key constraint (client has sales)SMS Templates
List SMS Templates
Get Templates (AJAX)
Response
Create SMS Template
string
required
Template name (max 100 characters)
text
required
Message template. Use
{nombre} placeholder for personalization.boolean
default:"true"
Active status
Update SMS Template
Delete SMS Template
SMS Campaigns
Send SMS to Clients
array
required
Array of client IDs to send SMS to
string
required
Message content. Use
{nombre} for personalization.string
Campaign name (optional, auto-generated if not provided)
Response
Message Personalization
The{nombre} placeholder is replaced with each client’s name:
Business Logic
Client Protection
Clients cannot be deleted if they have associated sales:ProtectedError exception raised
Multi-Tenancy
Clients are isolated per user:- Admin users see only their own clients
- Vendedor users see clients owned by their
creado_poradmin - Enforced via:
Cliente.objects.filter(usuario=request.user)
SMS Campaign Tracking
Each SMS sent creates anSMSLog entry:
- Links to campaign and client
- Stores Twilio SID for tracking
- Records success/failure status
- Logs error messages
total_clientes- Recipients countenviados_exitosos- Success countenviados_fallidos- Failure countestado- Overall campaign status
Example Workflow
Related Endpoints
- Sales API - Client sales transactions
- See source:
applications/clientes/models.pyandapplications/clientes/views.py