Create Releated Product
Create a new related product.
HTTP Request
POST/api/products/:product_id/related
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| product_id | integer | Yes | The unique identifier of the product |
Authorization
Authorization
- Required: Yes
- Permission: Staff or Admin
- Authentication: Token-based (Authorization: Token <your_api_key>)
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
| products | Array[int] | Yes | Array of related product IDs |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2response = requests.post('http://www.example.com/api/products/123/related',
3 json={
4 'products': [456, 789, 101]
5 },
6 headers={'Authorization': 'Token <your_token>'}
7
8 print(response.json())
9)1curl -X POST "http://www.example.com/api/products/123/related" -H "Authorization: Token <your_token>" -H "Content-Type: application/json" -d '{
2 "products": [456, 789, 101]
3}'Status Codes
| Code | Description |
|---|---|
| 201 | Related products created successfully |
| 400 | Bad Request - Invalid input data |
| 401 | Unauthorized - Invalid or missing API key |
| 403 | Forbidden - Access denied |
| 404 | Not Found - Product not found |
| 500 | Internal Server Error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the related product entry |
| active | Boolean | Whether the relation 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 the relation was created |
| updated_at | String (ISO 8601) | Timestamp when the relation 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 |