List Customers
Retrieves a list of all customers with filtering, searching, and ordering capabilities.
HTTP Request
GET/api/customers
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| limit | integer | 10 | Number of results to return per page |
| offset | integer | 0 | Number of results to skip before returning results |
| search | string | — | Search term to filter results by id, username, mobile_number, email, first_name, last_name |
| ordering | string | — | Field to order results by (id, username, email, gender, last_login, created_at, updated_at) |
| has_email | boolean | — | Filter customers with/without email address |
| has_avatar | boolean | — | Filter customers with/without avatar |
| has_phone | boolean | — | Filter customers with/without phone number |
| has_token | boolean | — | Filter customers with/without authentication token |
| has_first_name | boolean | — | Filter customers with/without first name |
| has_last_name | boolean | — | Filter customers with/without last name |
| is_active | boolean | — | Filter by active status |
| is_profile_completed | boolean | — | Filter by profile completion status |
| is_online | boolean | — | Filter by online status |
| gender | string | — | Filter by gender (male, female, etc.) |
| groups_in | string | — | Filter by multiple group IDs (comma-separated: 1,2,3) |
| group_id | integer | — | Filter by specific group ID |
| last_login_date | string | — | Filter by last login date (e.g., 2023-01-01) |
| last_login_from | string | — | Filter by last login date range start |
| last_login_to | string | — | Filter by last login date range end |
| id_min | integer | — | Minimum ID filter |
| id_max | integer | — | Maximum ID filter |
| created_date | string | — | Filter by creation date (e.g., 2023-01-01) |
| updated_date | string | — | Filter by last updated date (e.g., 2023-01-01) |
| created_from | string | — | Filter by creation date range start |
| created_to | string | — | Filter by creation date range end |
| updated_from | string | — | Filter by last updated date range start |
| updated_to | string | — | Filter by last updated date range end |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# List all customers
4response = requests.get('http://www.example.com/api/customers',
5 headers={'Authorization': 'Token <your_api_key>'}
6)
7print(response.json())
8
9# Search for customers with filters
10response = requests.get('http://www.example.com/api/customers', params={
11 'search': 'john',
12 'is_active': True,
13 'has_email': True,
14 'ordering': '-created_at',
15 'limit': 20
16}, headers={'Authorization': 'Token <your_api_key>'})
17print(response.json())
18
19# Filter by gender and online status
20response = requests.get('http://www.example.com/api/customers', params={
21 'gender': 'male',
22 'is_online': True,
23 'last_login_from': '2023-01-01'
24}, headers={'Authorization': 'Token <your_api_key>'})
25print(response.json())1# List all customers
2curl "http://www.example.com/api/customers" -H "Authorization: Token <your_api_key>"
3
4# Search with filters
5curl "http://www.example.com/api/customers?search=john&is_active=true&has_email=true&ordering=-created_at&limit=20" \
6-H "Authorization: Token <your_api_key>"
7
8# Filter by gender and online status
9curl "http://www.example.com/api/customers?gender=male&is_online=true&last_login_from=2023-01-01" \
10-H "Authorization: Token <your_api_key>"Status Codes
| Code | Description |
|---|---|
| 200 | Customers retrieved successfully |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the customer |
| username | String | Customer's username |
| mobile_number | String | Customer's phone number |
| String | Customer's email address | |
| avatar | String | URL to customer's avatar image |
| first_name | String | Customer's first name |
| last_name | String | Customer's last name |
| full_name | String | Customer's full name (computed field) |
| gender | String | Customer's gender (male/female) |
| is_active | Boolean | Whether the customer account is active |
| is_profile_completed | Boolean | Whether the customer has completed their profile |
| last_login | String (ISO 8601) | Timestamp of customer's last login |
| created_at | String (ISO 8601) | Timestamp when customer was created |
| updated_at | String (ISO 8601) | Timestamp when customer was last updated |
| is_online | Boolean | Whether the customer is currently online |
Notes
- Search works across multiple fields: id, username, mobile number, email, first name, and last name
- Use boolean filters (has_email, has_avatar, etc.) to find customers with or without specific attributes
- The is_online field indicates current activity status based on authentication token usage
- Date range filtering supports both specific dates and range queries for creation and login timestamps