Get All Related Products
Retrieve a list of products with optional filtering, searching, and pagination.
HTTP Request
GET/api/shop/products/:product_id/related
Authorization
Authorization
- Required: No
- Permission: Public (read-only)
- Authentication: Optional (affects `is_favorite` field)
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| product_id | Integer | Yes | Unique ID of the main product |
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# Get related products
4response = requests.get('http://www.example.com/api/shop/products/123/related')
5print(response.json())
6
7# With authentication for favorites
8response = requests.get('http://www.example.com/api/shop/products/123/related', headers={
9 'Authorization': 'Token <your_api_key>'
10})
11print(response.json())1# Without authentication
2curl "http://www.example.com/api/shop/products/123/related"
3
4# With authentication
5curl "http://www.example.com/api/shop/products/123/related" -H "Authorization: Token <your_api_key>"Status Codes
| Code | Description |
|---|---|
| 200 | Related products retrieved successfully |
| 404 | Main product not found |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the product |
| image | Object | Product image data (`id`, `url`, `name`, etc.) |
| code | String | Product code/SKU |
| name | String | Product name |
| slug | String | URL-friendly product identifier |
| stock_type | String | Type of stock management |
| in_stock | Boolean | Whether product is in stock |
| stock | Integer | Current stock quantity |
| regular_price | Decimal | Regular price of the product |
| sale_price | Decimal | Sale price (if on sale) |
| discount | Decimal | Discount amount |
| discount_percent | Decimal | Discount percentage |
| price | Decimal | Final calculated price |
| rating | Decimal | Average product rating |
| comments_count | Integer | Number of product comments/reviews |
| price_notes | String | Additional price information |
| excerpt | String | Short product description |
| is_favorite | Boolean | Whether product is in user's favorites (requires auth) |
| brand_data | Object | Brand information (`id`, `name`, `slug`) |
| category_data | Array[Object] | Category information (`id`, `name`, `slug`) |
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) |
| thumbnails | List of thumbnail objects | Imgae thumbnails |
Thumbnail Data Structure
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the thumbnail (unique) |
| f | String | URL to access the thumbnail file |
| size | Integer | File size in bytes (nullable) |
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 |
Example Response
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 36,
"image": {
"id": 2,
"type": "image",
"name": "logitech-mx-1",
"size": 4766,
"human_readable_size": "4.65 KB",
"f": "http://127.0.0.1:8000/media/core_media/2025/11/22/logitech-mx-1.jpg",
"width": 225,
"height": 225,
"mode": "RGB",
"thumbnails": [
{
"id": 213,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_64x64.jpg",
"size": 64
},
{
"id": 214,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_128x128.jpg",
"size": 128
},
{
"id": 215,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_512x512.jpg",
"size": 512
},
{
"id": 216,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_1080x1080.jpg",
"size": 1080
}
]
},
"code": "1001001",
"title": "ماوس لاجیتک MX Vertical",
"slug": "logitech-mouse-mx-vertical",
"stock_type": "limited",
"in_stock": true,
"stock": 4,
"regular_price": 12000000,
"sale_price": 10760000,
"discount": 1240000,
"discount_percent": 10,
"price": 10760000,
"rating": 1.0,
"comments_count": 1,
"price_notes": "قیمت فروش",
"excerpt": "<p style=\"text-align: right;\">ماوس «MX VERTICA» از سری محصولات خاص و مطرح برند شناخته‌شده‌ی لایجیتک (Logitech) است. این محصول لاجیتک با استفاده سه راه مختلف به کامپیوتر یا لپ‌تاپ شما متصل می‌شود. این راه‌ها شامل گیرنده وایرلس بی‌سیم ....USB، فناوری هوشمند بلوتوث و یا کابل شارژ USB-C ....</p>",
"is_favorite": false,
"brand": {
"id": 1,
"name": "Logitech",
"slug": "logitech"
},
"categories": [
{
"id": 2,
"name": "ماوس",
"slug": "mouse"
}
]
}
]
}
Notes
- Related products are returned using the same serializer as the product listing
- The endpoint combines manually set related products with category-based recommendations
- Products are automatically excluded from their own related products list
- All related products inherit the same filtering and computed field logic as the main product listing