Update Product
Update an existing product.
HTTP Request
PATCH/api/products/: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 product to update |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| name | String | Yes | Product name |
| code | String | No | Product code/SKU |
| slug | String | No | URL-friendly product identifier |
| active | Boolean | No | Whether the product is active (default: true) |
| image | Integer | No | ID of the product's main image |
| order | Integer | No | Display order priority |
| brand | Integer | No | Brand ID |
| categories | Array of Integers | No | List of Category IDs |
| stock_type | String | No | Stock management type |
| stock | Integer | No | Available stock quantity |
| regular_price | Decimal | No | Original price of the product |
| sale_price | Decimal | No | Sale price (if on sale) |
| price_notes | String | No | Additional pricing notes |
| excerpt | String | No | Short product description |
| description | String | No | Full product description |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# Partial update (PATCH)
4response = requests.patch('http://www.example.com/api/products/123',
5 json={
6 'name': 'Updated Gaming Laptop Pro',
7 'sale_price': 899.99,
8 'stock': 25,
9 'active': True
10 },
11 headers={'Authorization': 'Token <your_api_key>'}
12)
13print(response.json())
14
15# Update price and stock
16response = requests.patch('http://www.example.com/api/products/123',
17 json={
18 'regular_price': 1399.99,
19 'sale_price': 1099.99,
20 'stock': 100
21 },
22 headers={'Authorization': 'Token <your_api_key>'}
23)
24print(response.json())1# Partial update (PATCH)
2curl -X PATCH "http://www.example.com/api/products/123" -H "Authorization: Token <your_api_key>" -H "Content-Type: application/json" -d '{
3 "name": "Updated Gaming Laptop Pro",
4 "sale_price": 899.99,
5 "stock": 25,
6 "active": true
7}'
8
9# Update price and stock
10curl -X PATCH "http://www.example.com/api/products/123" -H "Authorization: Token <your_api_key>" -H "Content-Type: application/json" -d '{
11 "regular_price": 1399.99,
12 "sale_price": 1099.99,
13 "stock": 100
14}'Status Codes
| Code | Description |
|---|---|
| 200 | Product updated successfully |
| 400 | Bad request — invalid input |
| 401 | Unauthorized — authentication required |
| 403 | Forbidden — insufficient permissions |
| 404 | Not found — product does not exist |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the product |
| active | Boolean | Whether the product is active |
| image_data | Object | Image details (read-only) |
| order | Integer | Display order priority |
| code | String | Product code/SKU |
| name | String | Product name |
| slug | String | URL-friendly product identifier |
| stock_type | String | Stock management type |
| stock | Integer | Available stock quantity |
| in_stock | Boolean | Whether the product is in stock (computed) |
| regular_price | Decimal | Original price of the product |
| sale_price | Decimal | Sale price (if on sale) |
| discount | Decimal | Discount amount (computed) |
| discount_percent | Decimal | Discount percentage (computed) |
| price | Decimal | Final price after discount (computed) |
| price_notes | String | Additional pricing notes |
| excerpt | String | Short product description |
| comments_count | Integer | Number of comments (computed) |
| rating | Decimal | Average product rating (computed) |
| description | String | Full product description |
| created_at | String (ISO 8601) | Timestamp when product was created |
| updated_at | String (ISO 8601) | Timestamp when product was last updated |
| brand_data | Object | Brand details (id: int, name: string) |
| categories_data | Array[Object] | List of categories the product belongs to (id: int, name: string) |
Image Data Structure
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the image |
| type | String | File type (e.g., image/jpeg) |
| name | String | Original file name |
| size | Integer | File size in bytes |
| human_readable_size | String | Human readable file size (e.g., 2.5 MB) |
| f | String | URL to access the image file |
| width | Integer | Image width in pixels |
| height | Integer | Image height in pixels |
| mode | String | Color mode (e.g., RGB, CMYK) |
Brand Data Structure
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the brand |
| name | String | Name of the brand |
Categories Data Structure
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the category |
| name | String | Name of the category |
Notes
- Fields marked as "computed" are generated by the system and cannot be set directly.
- Date fields are in ISO 8601 format (e.g., "2023-01-01T12:00:00Z").