Addresses
Manages customer shipping/billing addresses with full CRUD operations.
HTTP Request
Retrieve Addresses:
GET/api/shop/customers/me/addresses
Create Address:
POST/api/shop/customers/me/addresses
Update Address:
PATCH/api/shop/customers/me/addresses/:id
Delete Address:
DELETE/api/shop/customers/me/addresses/:id
Authorization
Authorization
- Required: Yes
- Permission: Authenticated Customer
- Authentication: Token-based (`Authorization: Token <your_api_key>`)
Query Parameters (GET only)
| Parameter | Type | Default | Description |
|---|---|---|---|
| limit | integer | — | Number of results to return per page |
| offset | integer | — | Number of results to skip |
| search | string | — | Search in `first_name`, `last_name`, `postal_code`, `address` |
| ordering | string | — | Field to order results by (`id`, `country`, `state`, `city`, `created_at`, `updated_at`, `default`) |
| country_in | string | — | Filter by multiple country IDs (comma-separated) |
| state_in | string | — | Filter by multiple state IDs (comma-separated) |
| city_in | string | — | Filter by multiple city IDs (comma-separated) |
| country_id | integer | — | Filter by specific country ID |
| state_id | integer | — | Filter by specific state ID |
| city_id | integer | — | Filter by specific city ID |
| has_national_code | boolean | — | Filter addresses with/without national code |
| id_min | integer | — | Minimum ID filter |
| id_max | integer | — | Maximum ID filter |
| created_date | string | — | Filter by creation date |
| updated_date | string | — | Filter by last updated date |
| 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 |
Request Body (POST only)
| Field | Type | Required | Description |
|---|---|---|---|
| default | Boolean | No | Set as default address |
| country | Integer | Yes | Country ID |
| state | Integer | Yes | State ID |
| city | Integer | Yes | City ID |
| address | String | Yes | Detailed address |
| postal_code | String | Yes | Postal/ZIP code |
| first_name | String | Yes | Recipient's first name |
| last_name | String | Yes | Recipient's last name |
| national_code | String | No | National identification code |
| mobile_number | String | Yes | Recipient's mobile number |
Path Parameters (PATCH, DELETE only)
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | Integer | Yes | Unique ID of the address |
Request Body (PATCH only)
| Field | Type | Required | Description |
|---|---|---|---|
| default | Boolean | No | Set as default address |
| country | Integer | No | Country ID |
| state | Integer | No | State ID |
| city | Integer | No | City ID |
| address | String | No | Detailed address |
| postal_code | String | No | Postal/ZIP code |
| first_name | String | No | Recipient's first name |
| last_name | String | No | Recipient's last name |
| national_code | String | No | National identification code |
| mobile_number | String | No | Recipient's mobile number |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# List customer addresses
4response = requests.get('http://www.example.com/api/shop/customers/me/addresses',
5 params={
6 'ordering': '-created_at',
7 'limit': 20,
8 'search': 'john'
9 },
10 headers={'Authorization': 'Token <your_api_key>'}
11)
12print(response.json())
13
14# Create new address
15response = requests.post('http://www.example.com/api/shop/customers/me/addresses',
16 json={
17 'default': True,
18 'country': 1,
19 'state': 5,
20 'city': 15,
21 'address': '123 Main Street, Apt 4B',
22 'postal_code': '12345',
23 'first_name': 'John',
24 'last_name': 'Doe',
25 'mobile_number': '+1234567890'
26 },
27 headers={'Authorization': 'Token <your_api_key>'}
28)
29print(response.json())
30
31import requests
32
33# Get specific address
34response = requests.get('http://www.example.com/api/shop/customers/me/addresses/123',
35 headers={'Authorization': 'Token <your_api_key>'}
36)
37print(response.json())
38
39# Update address
40response = requests.patch('http://www.example.com/api/shop/customers/me/addresses/123',
41 json={
42 'default': True,
43 'postal_code': '54321'
44 },
45 headers={'Authorization': 'Token <your_api_key>'}
46)
47print(response.json())
48
49# Delete address
50response = requests.delete('http://www.example.com/api/shop/customers/me/addresses/123',
51 headers={'Authorization': 'Token <your_api_key>'}
52)
53print(response.status_code) # Should be 2041# List customer addresses with filters
2curl "http://www.example.com/api/shop/customers/me/addresses?ordering=-created_at&limit=20&country_id=1" -H "Authorization: Token <your_api_key>"
3
4# Create new address
5curl -X POST "http://www.example.com/api/shop/customers/me/addresses" -H "Authorization: Token <your_api_key>" -H "Content-Type: application/json" -d '{
6 "default": true,
7 "country": 1,
8 "state": 5,
9 "city": 15,
10 "address": "123 Main Street, Apt 4B",
11 "postal_code": "12345",
12 "first_name": "John",
13 "last_name": "Doe",
14 "mobile_number": "+1234567890"
15}'
16
17# Get specific address
18curl "http://www.example.com/api/shop/customers/me/addresses/123" -H "Authorization: Token <your_api_key>"
19
20# Update address
21curl -X PATCH "http://www.example.com/api/shop/customers/me/addresses/123" -H "Authorization: Token <your_api_key>" -H "Content-Type: application/json" -d '{
22 "default": true,
23 "postal_code": "54321"
24}'
25
26# Delete address
27curl -X DELETE "http://www.example.com/api/shop/customers/me/addresses/123" -H "Authorization: Token <your_api_key>"Status Codes
| Code | Description |
|---|---|
| 200 | Address retrieved/updated successfully |
| 204 | Address deleted successfully |
| 400 | Bad request — validation errors |
| 401 | Unauthorized — authentication required |
| 404 | Address not found |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the address |
| default | Boolean | Whether this is the default address |
| country_data | Object | Country details (read-only) |
| state_data | Object | State details (read-only) |
| city_data | Object | City details (read-only) |
| address | String | Detailed address |
| postal_code | String | Postal/ZIP code |
| first_name | String | Recipients first name |
| last_name | String | Recipients last name |
| national_code | String | National identification code |
| mobile_number | String | Recipients mobile number |
| text | String | Additional notes |
| created_at | String (ISO 8601) | Timestamp when address was created |
| updated_at | String (ISO 8601) | Timestamp when address was last updated |
Country/State Data Structure:
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID |
| name | String | Name of the country/state |
| code | String | Code (e.g., ISO code for country) |
City Data Structure:
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID |
| name | String | Name of the city |
Notes
- Geographic Validation: State must belong to the specified country, and city must belong to the specified state
- Access Control: Customers can only access their own addresses
- Default Address: Only one address can be set as default per customer