Update Customer
Updates an existing customer's information.
HTTP Request
PATCH/api/customers/:id
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | Integer | Yes | Unique ID of the customer |
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 (must be unique) | |
| 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 |
| is_active | Boolean | No | Whether the customer account should be active |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# Partial update (PATCH) - update only specific fields
4response = requests.patch('http://www.example.com/api/customers/123',
5 json={
6 'email': 'newemail@example.com',
7 'mobile_number': '+9876543210',
8 'notes': 'Updated customer information'
9 },
10 headers={'Authorization': 'Token <your_api_key>'}
11)
12print(response.json())
13
14# Update customer status
15response = requests.patch('http://www.example.com/api/customers/123',
16 json={
17 'is_active': False,
18 'notes': 'Customer account deactivated'
19 },
20 headers={'Authorization': 'Token <your_api_key>'}
21)
22print(response.json())
23
24# Full update (PUT) - updates all fields
25response = requests.put('http://www.example.com/api/customers/123',
26 json={
27 'first_name': 'John',
28 'last_name': 'Smith',
29 'email': 'john.smith@example.com',
30 'mobile_number': '+1234567890',
31 'national_code': '9876543210',
32 'birth_date': '1985-05-15',
33 'gender': 'male',
34 'notes': 'VIP customer - expedite all orders',
35 'is_active': True
36 },
37 headers={'Authorization': 'Token <your_api_key>'}
38)
39print(response.json())1# Partial update (PATCH)
2curl -X PATCH "http://www.example.com/api/customers/123" \
3-H "Authorization: Token <your_api_key>" \
4-H "Content-Type: application/json" \
5-d '{
6 "email": "newemail@example.com",
7 "mobile_number": "+9876543210",
8 "notes": "Updated customer information"
9}'
10
11# Update customer status
12curl -X PATCH "http://www.example.com/api/customers/123" \
13-H "Authorization: Token <your_api_key>" \
14-H "Content-Type: application/json" \
15-d '{
16 "is_active": false,
17 "notes": "Customer account deactivated"
18}'
19
20# Full update (PUT)
21curl -X PUT "http://www.example.com/api/customers/123" \
22-H "Authorization: Token <your_api_key>" \
23-H "Content-Type: application/json" \
24-d '{
25 "first_name": "John",
26 "last_name": "Smith",
27 "email": "john.smith@example.com",
28 "mobile_number": "+1234567890",
29 "national_code": "9876543210",
30 "birth_date": "1985-05-15",
31 "gender": "male",
32 "notes": "VIP customer - expedite all orders",
33 "is_active": true
34}'Status Codes
| Code | Description |
|---|---|
| 200 | Customer updated successfully |
| 400 | Bad request — invalid input or validation error |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 404 | Customer not found |
| 409 | Conflict — email already exists for another customer |
| 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 |
| is_profile_completed | Boolean | Whether the customer has completed their profile |
| date_joined | String (ISO 8601) | Timestamp when customer was created |
| 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
- Use PATCH for partial updates (recommended) - only send fields you want to change
- Use PUT for full updates - replaces all customer data with provided values
- Email addresses must be unique across the system
- Setting is_active to false will disable customer access but preserve data
- Gender field accepts only 'M' (Male) or 'F' (Female)
- Birth date must be in YYYY-MM-DD format
- total_orders and total_spent are calculated fields and cannot be directly updated