Skip to main content

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

ParameterTypeRequiredDescription
idIntegerYesUnique ID of the customer

Request Body

FieldTypeRequiredDescription
first_nameStringNoCustomer's first name
last_nameStringNoCustomer's last name
emailStringNoCustomer's email address (must be unique)
mobile_numberStringNoCustomer's mobile phone number
national_codeStringNoCustomer's national identification code
birth_dateString (YYYY-MM-DD)NoCustomer's birth date in YYYY-MM-DD format
genderStringNoCustomer's gender (male/female)
notesStringNoAdditional notes about the customer
is_activeBooleanNoWhether the customer account should be active

Example Requests

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())

Status Codes

CodeDescription
200Customer updated successfully
400Bad request — invalid input or validation error
401Unauthorized — authentication required
403Forbidden — insufficient permissions
404Customer not found
409Conflict — email already exists for another customer
500Internal server error

Response Fields

FieldTypeDescription
idIntegerUnique ID of the customer
first_nameStringCustomer's first name
last_nameStringCustomer's last name
emailStringCustomer's email address
mobile_numberStringCustomer's mobile phone number
national_codeStringCustomer's national identification code
birth_dateString (YYYY-MM-DD)Customer's birth date
genderStringCustomer's gender (male/female)
notesStringAdditional notes about the customer
is_activeBooleanWhether the customer account is active
is_profile_completedBooleanWhether the customer has completed their profile
date_joinedString (ISO 8601)Timestamp when customer was created
last_loginString (ISO 8601)Timestamp of customer's last login (null if never logged in)
total_ordersIntegerTotal number of orders placed by this customer
total_spentString (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