Create Customer
Creates a new customer in the system.
HTTP Request
POST/api/customers
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| first_name | String | No | Customer's first name |
| last_name | String | No | Customer's last name |
| String | No | Customer's email address | |
| mobile_number | String | No | Customer's mobile phone number |
| national_code | String | No | Customer's national identification code |
| birth_date | String (YYYY-MM-DD) | No | Customer's birth date in YYYY-MM-DD format |
| gender | String | No | Customer's gender (male, female) |
| notes | String | No | Additional notes about the customer |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# Create a new customer with full details
4response = requests.post('http://www.example.com/api/customers',
5 json={
6 'first_name': 'John',
7 'last_name': 'Doe',
8 'email': 'john.doe@example.com',
9 'mobile_number': '+1234567890',
10 'national_code': '1234567890',
11 'birth_date': '1990-01-15',
12 'gender': 'male',
13 'notes': 'VIP customer'
14 },
15 headers={'Authorization': 'Token <your_api_key>'}
16)
17print(response.json())
18
19# Create minimal customer
20response = requests.post('http://www.example.com/api/customers',
21 json={
22 'email': 'jane.smith@example.com',
23 'first_name': 'Jane'
24 },
25 headers={'Authorization': 'Token <your_api_key>'}
26)
27print(response.json())1# Create a new customer with full details
2curl -X POST "http://www.example.com/api/customers" \
3-H "Authorization: Token <your_api_key>" \
4-H "Content-Type: application/json" \
5-d '{
6 "first_name": "John",
7 "last_name": "Doe",
8 "email": "john.doe@example.com",
9 "mobile_number": "+1234567890",
10 "national_code": "1234567890",
11 "birth_date": "1990-01-15",
12 "gender": "male",
13 "notes": "VIP customer"
14}'
15
16# Create minimal customer
17curl -X POST "http://www.example.com/api/customers" \
18-H "Authorization: Token <your_api_key>" \
19-H "Content-Type: application/json" \
20-d '{
21 "email": "jane.smith@example.com",
22 "first_name": "Jane"
23}'Status Codes
| Code | Description |
|---|---|
| 201 | Customer created successfully |
| 400 | Bad request — invalid input or validation error |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 409 | Conflict — customer with this email already exists |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the customer |
| first_name | String | Customer's first name |
| last_name | String | Customer's last name |
| String | Customer's email address | |
| mobile_number | String | Customer's mobile phone number |
| national_code | String | Customer's national identification code |
| birth_date | String (YYYY-MM-DD) | Customer's birth date |
| gender | String | Customer's gender (male/female) |
| notes | String | Additional notes about the customer |
| is_active | Boolean | Whether the customer account is active |
| date_joined | String (ISO 8601) | Timestamp when customer was created |
| is_profile_completed | Boolean | Whether the customer has completed their profile |
| last_login | String (ISO 8601) | Timestamp of customer's last login (null if never logged in) |
| total_orders | Integer | Total number of orders placed by this customer |
| total_spent | String (Decimal) | Total amount spent by this customer |
Notes
- All fields are optional when creating a customer
- Email addresses must be unique across the system
- Gender field accepts only 'M' (Male) or 'F' (Female)
- Birth date must be in YYYY-MM-DD format
- Mobile number should include country code
- New customers are automatically set to active status
- total_orders and total_spent are calculated fields that start at 0