Why is the section_id required when I get product recommendations

From the Recommendations API docs, I see that I can get the product recommendations back in two formats depending on the query parameters

  • product_id with no section_id returns JSON
  • product_id with section_id returns HTML

https://shopify.dev/docs/themes/ajax-api/reference/product-recommendations#get-recommendations-products-json

I’m having trouble with the JSON response format – I receive an error response telling me that the section_id parameter is missing

Without section_id

Query:

https://mill-and-commons.myshopify.com/recommendations/products?product_id=6212544266414&limit=4

Response:

The HTML response comes as expected

With section_id

Query:

https://mill-and-commons.myshopify.com/recommendations/products?product_id=6212544266414&limit=4&section_id=product_recommendations

Response:

To get the JSON object you need to append .json to the endpoint. In your case the AJAX request would be

https://mill-and-commons.myshopify.com/recommendations/products.json?product_id=6212544266414&limit=4