Skip to main content

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 (effects `is_favorite` field)

Path Parameters​

ParameterTypeRequiredDescription
product_idIntegerYesUnique ID of the main product

Example Requests​

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

Status Codes​

CodeDescription
200Related products retrieved successfully
404Main product not found
500Internal server error

Response Fields​

FieldTypeDescription
countIntegerTotal number of categories
nextStringURL for the next page of results
previousStringURL for the previous page of results
resultsArray[Object]Array of related product objects

RelatedProduct Object Structure

FieldTypeDescription
idIntegerUnique ID of the product
imageObjectProduct image data (`id`, `url`, `name`, etc.)
codeStringProduct code/SKU
titleStringProduct title
slugStringURL-friendly product identifier
stock_typeStringType of stock management
in_stockBooleanWhether product is in stock
stockIntegerCurrent stock quantity
regular_priceDecimalRegular price of the product
sale_priceDecimalSale price (if on sale)
discountDecimalDiscount amount
discount_percentDecimalDiscount percentage
priceDecimalFinal calculated price
ratingDecimalAverage product rating
comments_countIntegerNumber of product comments/reviews
price_notesStringAdditional price information
excerptStringShort product description
is_favoriteBooleanWhether product is in user's favorites (requires auth)
brandObjectBrand information (`id`, `name`, `slug`)
categoriesArray[Object]Category information (`id`, `name`, `slug`)

Image Data Structure

FieldTypeDescription
idIntegerUnique ID of the image
typeStringFile type (e.g., image)
mime_typeStringMime type of the File (e.g., image/jpeg) (nullable)
nameStringOriginal file name
sizeIntegerFile size in bytes
human_readable_sizeStringHuman readable file size (e.g., 2.5 MB)
fStringURL to access the image file
widthIntegerImage width in pixels
heightIntegerImage height in pixels
modeStringColor mode (e.g., RGB, CMYK)
thumbnailsList of thumbnail objectsImgae thumbnails

Thumbnail Data Structure

FieldTypeDescription
idIntegerUnique ID of the thumbnail (unique)
fStringURL to access the thumbnail file
sizeIntegerFile size in bytes (nullable)

Brand Data Structure

FieldTypeDescription
idIntegerUnique ID of the brand
nameStringName of the brand

Categories Data Structure

FieldTypeDescription
idIntegerUnique ID of the category
nameStringName of the category

Example Response​

{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 36,
"image": {
"id": 2,
"type": "image",
"mime_type": "image/jpeg",
"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;\">ماوس &laquo;MX VERTICA&raquo; از سری محصولات خاص و مطرح برند شناخته&zwnj;شده&zwnj;ی لایجیتک (Logitech) است. این محصول لاجیتک با استفاده سه راه مختلف به کامپیوتر یا لپ&zwnj;تاپ شما متصل می&zwnj;شود. این راه&zwnj;ها شامل گیرنده وایرلس بی&zwnj;سیم ....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