Skip to main content

Retrieve Product Metadata

Retrieves aggregated metadata about products, including total count and price/discount ranges. This endpoint is useful for building product filters, price ranges, and analytics dashboards.

HTTP Request

GET/api/shop/products/metadata

Authorization

Authorization

  • Required: No
  • Permission: Public (read-only)
  • Authentication: None

Query Parameters

This endpoint supports all the same filtering parameters as the List Products endpoint to get metadata for specific product subsets:

ParameterTypeDefaultDescription
searchstringSearch term to filter products before calculating metadata
brand_idintegerFilter by specific brand ID
brand_instringFilter by multiple brand IDs (comma-separated: `1,2,3`)
category_idintegerFilter by specific category ID
category_instringFilter by multiple category IDs (comma-separated: `1,2,3`)
category_tree_idintegerFilter by category tree ID (returns metadata for products in the category and subcategories)
regular_price_minnumberMinimum regular price filter
regular_price_maxnumberMaximum regular price filter
sale_price_minnumberMinimum sale price filter
sale_price_maxnumberMaximum sale price filter
price_minnumberMinimum final price filter
price_maxnumberMaximum final price filter
has_discountbooleanFilter products with/without discount
discount_minnumberMinimum discount amount filter
discount_maxnumberMaximum discount amount filter
discount_percent_minnumberMinimum discount percentage filter
discount_percent_maxnumberMaximum discount percentage filter
in_stockbooleanFilter by stock availability
has_imagebooleanFilter products with/without image
has_commentsbooleanFilter products with/without comments
comments_count_minintegerMinimum comments count filter
comments_count_maxintegerMaximum comments count filter
rating_minnumberMinimum rating filter
rating_maxnumberMaximum rating filter
id_minintegerMinimum ID filter
id_maxintegerMaximum ID filter
created_datestringFilter by creation date (e.g., `2023-01-01`)
updated_datestringFilter by last updated date (e.g., `2023-01-01`)
created_fromstringFilter by creation date range start
created_tostringFilter by creation date range end
updated_fromstringFilter by last updated date range start
updated_tostringFilter by last updated date range end

Example Requests

1import requests
2
3# Get metadata for all products
4response = requests.get('http://www.example.com/api/shop/products/metadata')
5print(response.json())
6
7# Get metadata for specific category
8response = requests.get('http://www.example.com/api/shop/products/metadata', params={
9  'category_id': 1
10})
11print(response.json())
12
13# Get metadata for products with discounts
14response = requests.get('http://www.example.com/api/shop/products/metadata', params={
15  'has_discount': True
16})
17print(response.json())
18
19# Get metadata for specific brand and price range
20response = requests.get('http://www.example.com/api/shop/products/metadata', params={
21  'brand_id': 5,
22  'price_min': 100,
23  'price_max': 1000
24})
25print(response.json())
26
27# Get metadata for search results
28response = requests.get('http://www.example.com/api/shop/products/metadata', params={
29  'search': 'smartphone'
30})
31print(response.json())

Status Codes

CodeDescription
200Metadata retrieved successfully
400Bad request — invalid query parameters
500Internal server error

Response Fields

FieldTypeDescription
total_productsintegerTotal number of products matching the filters
max_pricedecimal or nullHighest final price among filtered products
min_pricedecimal or nullLowest final price among filtered products
max_discountdecimal or nullHighest discount amount among filtered products
min_discountdecimal or nullLowest discount amount among filtered products
max_discount_percentdecimal or nullHighest discount percentage among filtered products
min_discount_percentdecimal or nullLowest discount percentage among filtered products

Example Response

{
"total_products": 150,
"max_price": 999.99,
"min_price": 49.99,
"max_discount": 200.00,
"min_discount": 10.00,
"max_discount_percent": 50.0,
"min_discount_percent": 5.0
}

Use Cases

Price Range Filters

Use the min_price and max_price values to set the bounds for price range sliders in your UI:

# Get price range for a category
response = requests.get('/api/products/metadata?category_id=1')
metadata = response.json()
price_slider_min = float(metadata['min_price'])
price_slider_max = float(metadata['max_price'])

Discount Information

Use discount metadata to show discount ranges and filter availability:

# Check if any products have discounts
response = requests.get('/api/products/metadata?has_discount=true')
metadata = response.json()
if metadata['total_products'] > 0:
max_discount_percent = float(metadata['max_discount_percent'])
print(f"Discounts up to {max_discount_percent}% available!")

Search Results Summary

Display result counts and price ranges for search results:

# Get metadata for search results
response = requests.get('/api/products/metadata?search=laptop')
metadata = response.json()
print(f"Found {metadata['total_products']} laptops")
print(f"Price range: ${metadata['min_price']} - ${metadata['max_price']}")

Analytics and Reporting

Use metadata for dashboard analytics:

# Compare categories
categories = [1, 2, 3]
for cat_id in categories:
response = requests.get(f'/api/products/metadata?category_id={cat_id}')
metadata = response.json()
print(f"Category {cat_id}: {metadata['total_products']} products")

Performance Notes

  • Caching: This endpoint supports caching to improve performance for frequently requested metadata
  • Filtering Impact: All filters are applied before calculating aggregations, so metadata reflects the filtered dataset
  • Real-time Data: Metadata is calculated from the current state of the database, including real-time price and discount calculations
  • Search Performance: When using search parameters, metadata calculation may take longer due to text search operations

Notes

  • All price and discount values are calculated using the same logic as the product listing endpoints
  • Null values may be returned for min/max fields if no products match the filters
  • The total_products count reflects only active products that match all applied filters
  • Search functionality supports the same operators and syntax as the main product search
  • This endpoint is particularly useful for building dynamic UI components like price sliders and filter summaries