Open Source CRM developed on Django framework with REST API for contact, lead, account, and opportunity management
Authentication, user management, organization management, and administrative functions for the Django CRM system. The system uses JWT authentication with organization-based multi-tenancy and role-based access control.
Django CRM uses JWT (JSON Web Tokens) for API authentication with access and refresh token support.
def refresh_token(refresh_token: str) -> dict:
"""
Refresh JWT access token using refresh token.
Args:
refresh_token (str): Valid refresh token
Returns:
dict: New access token and optional refresh token
Example:
POST /api/auth/refresh-token/
{
"refresh": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
}
Response:
{
"access": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9..."
}
"""Google OAuth integration for seamless user authentication and account creation.
def google_login(google_token: str) -> dict:
"""
Authenticate user with Google OAuth token.
Args:
google_token (str): Valid Google OAuth access token
Returns:
dict: JWT access and refresh tokens with user information
Example:
POST /api/auth/google/
{
"token": "ya29.a0ARrdaM-google-oauth-token..."
}
Response:
{
"access": "jwt_access_token",
"refresh": "jwt_refresh_token",
"user": {
"id": "user-uuid",
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe"
}
}
"""Get dashboard overview data including counts and recent activity across all CRM entities.
def get_dashboard() -> dict:
"""
Get dashboard statistics and overview data.
Returns:
dict: Dashboard data with entity counts and recent items
Headers Required:
Authorization: Bearer <access_token>
organization-id: <org_uuid>
Example:
GET /api/dashboard/
Response:
{
"accounts": {
"open_accounts": 25,
"closed_accounts": 5,
"accounts": [...list of recent accounts...]
},
"contacts": {
"contacts": [...list of recent contacts...]
},
"leads": {
"open_leads": 15,
"closed_leads": 3,
"leads": [...list of recent leads...]
},
"opportunities": {
"opportunities": [...list of recent opportunities...]
}
}
"""Manage current user's profile information and settings.
def get_profile() -> dict:
"""
Get current authenticated user's profile.
Returns:
dict: User profile information
Headers Required:
Authorization: Bearer <access_token>
Example:
GET /api/profile/
Response:
{
"id": "user-uuid",
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe",
"role": "USER",
"phone": "+1234567890",
"is_active": true,
"org": "org-uuid",
"address": {
"address_line": "123 Main St",
"city": "New York",
"state": "NY",
"postcode": "10001",
"country": "USA"
}
}
"""Administrative functions for managing users within an organization.
def list_users(email: str = None, role: str = None, status: str = None) -> dict:
"""
List users in organization with filtering.
Args:
email (str, optional): Filter by email
role (str, optional): Filter by role ('ADMIN' or 'USER')
status (str, optional): Filter by status ('Active' or 'Inactive')
Returns:
dict: Paginated list of users
Headers Required:
Authorization: Bearer <access_token> (Admin role)
organization-id: <org_uuid>
Example:
GET /api/users/?role=USER&status=Active
Response:
{
"count": 10,
"next": null,
"previous": null,
"results": [
{
"id": "user-uuid",
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe",
"role": "USER",
"is_active": true,
"phone": "+1234567890"
}
]
}
"""
def create_user(user_data: dict) -> dict:
"""
Create new user in organization.
Args:
user_data (dict): User information including email, name, role, phone, address
Returns:
dict: Created user information
Headers Required:
Authorization: Bearer <access_token> (Admin role)
organization-id: <org_uuid>
Example:
POST /api/users/
{
"email": "newuser@example.com",
"first_name": "Jane",
"last_name": "Smith",
"role": "USER",
"phone": "+1987654321",
"address": {
"address_line": "456 Oak Ave",
"city": "Boston",
"state": "MA",
"postcode": "02101",
"country": "USA"
}
}
"""
def get_user(pk: str) -> dict:
"""
Get detailed user information.
Args:
pk (str): User UUID
Returns:
dict: User details with associated data
Headers Required:
Authorization: Bearer <access_token>
Example:
GET /api/user/user-uuid/
Response:
{
"user_obj": {...user details...},
"address_obj": {...address details...},
"opportunities": [...user's opportunities...],
"contacts": [...user's contacts...],
"cases": [...user's cases...],
"comments": [...user's comments...]
}
"""
def update_user(pk: str, user_data: dict) -> dict:
"""
Update user information.
Args:
pk (str): User UUID
user_data (dict): Updated user information
Returns:
dict: Updated user information
Headers Required:
Authorization: Bearer <access_token>
Example:
PUT /api/user/user-uuid/
{
"first_name": "John",
"last_name": "Updated",
"phone": "+1555123456"
}
"""
def delete_user(pk: str) -> None:
"""
Delete user (Admin only).
Args:
pk (str): User UUID
Returns:
None: 204 No Content on success
Headers Required:
Authorization: Bearer <access_token> (Admin role)
Example:
DELETE /api/user/user-uuid/
"""
def update_user_status(pk: str, status: str) -> dict:
"""
Update user active/inactive status.
Args:
pk (str): User UUID
status (str): 'Active' or 'Inactive'
Returns:
dict: Success message
Headers Required:
Authorization: Bearer <access_token> (Admin role)
Example:
POST /api/user/user-uuid/status/
{
"status": "Inactive"
}
Response:
{
"status": "success",
"message": "User status updated successfully"
}
"""Get teams and users for dropdown/selection purposes across the application.
def get_teams_and_users() -> dict:
"""
Get teams and users for selection dropdowns.
Returns:
dict: Teams and user profiles lists
Headers Required:
Authorization: Bearer <access_token>
organization-id: <org_uuid>
Example:
GET /api/users/get-teams-and-users/
Response:
{
"teams": [
{
"id": "team-uuid",
"name": "Sales Team",
"description": "Sales representatives"
}
],
"profiles": [
{
"id": "user-uuid",
"user": "user-uuid",
"first_name": "John",
"last_name": "Doe"
}
]
}
"""Create and manage organizations for multi-tenant scoping.
def list_organizations() -> list:
"""
Get list of organizations user belongs to.
Returns:
list: User's organizations
Headers Required:
Authorization: Bearer <access_token>
Example:
GET /api/org/
Response:
[
{
"id": "org-uuid",
"name": "ACME Corporation",
"slug": "acme-corp",
"billing_city": "New York",
"billing_state": "NY"
}
]
"""
def create_organization(org_data: dict) -> dict:
"""
Create new organization.
Args:
org_data (dict): Organization information
Returns:
dict: Created organization details
Headers Required:
Authorization: Bearer <access_token>
Example:
POST /api/org/
{
"name": "New Company LLC"
}
Response:
{
"id": "new-org-uuid",
"name": "New Company LLC",
"slug": "new-company-llc"
}
"""All authenticated endpoints require these headers:
class AuthHeaders:
"""Required headers for authenticated requests"""
Authorization: str # "Bearer <access_token>"
organization_id: str # Organization UUID (for org-scoped operations)
class AdminRequiredHeaders(AuthHeaders):
"""Headers for admin-only endpoints - user must have ADMIN role"""
passclass UserRole:
"""User roles in the system"""
ADMIN: str = "ADMIN" # Full administrative access
USER: str = "USER" # Standard user access
class UserStatus:
"""User status options"""
ACTIVE: str = "Active"
INACTIVE: str = "Inactive"Common authentication and authorization errors:
Install with Tessl CLI
npx tessl i tessl/pypi-django-crm