Magento – Magento rest API configurable product and category list

apimagento2rest

I am having a project using Magento rest API V1, I have read through the documentation and looking for the answer around the web but cannot find the solution.

** First: **

I want to show list of configurable products and user will select the size before adding to cart, I am using :

{{domain}}/rest/V1/products?searchCriteria[filterGroups][0][filters][0][field]=has_options&searchCriteria[filterGroups][0][filters][01][value]=1&searchCriteria[pageSize]=10

**The response I get: **

{
  "items": [
    {
      "id": 1,
      "sku": "AA0001",
      "name": "Sample Product",
      "attribute_set_id": 1,
      "price": 0,
      "status": 1,
      "visibility": 4,
      "type_id": "configurable",
      ....
   },
   ....
]
   }

The problem is the price is 0, and I only want to show configurable product list.

** Second: **

I want to do a filter by size, color and another attribute for a specific category, how can I get a list of available attributes by category?
Like category_id = 1 and show what sizes are available only for that category.

Thanks in advance

Best Answer

I know it's an old question, but I hope someone would find it useful.

You need to use another endpoint to get the configurable product price.

/rest/V1/configurable-products/:sku/children

Each product children might be having their own price.

So you need to find a lower price or any reasonable way from the children to display the configurable product price in a category list. Also in default product detail display.

Because each product children might be having different price. You need to get the correct price based on the selected configurable product options.

You can see all the options below the "extension_attributes" -> "configurable_product_options" property or using below endpoint :

/rest/V1/configurable-products/:sku/options/all

To display the options correct values, you need to get all available product attributes using below endpoint :

/rest/V1/products/attributes?searchCriteria[filterGroups][0][filters][0][field]=is_visible&searchCriteria[filterGroups][0][filters][0][value]=1&searchCriteria[filterGroups][0][filters][0][conditionType]=eq&searchCriteria[filterGroups][1][filters][0][field]=is_user_defined&searchCriteria[filterGroups][1][filters][0][value]=1&searchCriteria[filterGroups][1][filters][0][conditionType]=eq

Check & modify the query param for your best result. Also by the time I answer this question, you cannot test this endpoint using plain Postman request, you need to pass the Authorization header.

Then display the options based on the "configurable_product_options" property.

Related Topic