5

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

  • To my mind if your logic is specific you need to create your custom API based on the Magento native API. You will have more control to manage the output. – Franck Garnier Dec 1 '16 at 7:56
1

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.

  • I have a problem which I return configurable products in many APIs, So I can't loop on each API to make it custom. Can you check this question magento.stackexchange.com/questions/189724/… – Jsparo30 Aug 20 '17 at 6:00
  • I'm also did that for now, because I'm not yet having time to find out where to override the output of this endpoint. But you can start checking the magento/module-catalog/etc/webapi.xml and repositories used there. – sule Aug 20 '17 at 10:09
  • Does any Magento 2 interface or api not leak profusely? – J. M. Becker Dec 16 '18 at 19:13
0

Here is the REST API call to filter only configurable product:

 http://magento2api.com/rest/V1/products?searchCriteria[pageSize]=5&searchCriteria[currentPage]=1&searchCriteria[filterGroups][0][filters][0][field]=type_id&searchCriteria[filterGroups][0][filters][0][value]=configurable&searchCriteria[filterGroups][0][filters][0][conditionType]=eq

postman screen image:

enter image description here

Result:

  {
"items": [{
    "id": 67,
    "sku": "MH01",
    "name": "Chaz Kangeroo Hoodie",
    "attribute_set_id": 9,
    "price": 0,
    "status": 1,
    "visibility": 4,
    "type_id": "configurable",
    "created_at": "2016-09-26 06:45:52",
    "updated_at": "2016-09-26 06:45:52",
    "extension_attributes": [],
    "product_links": [],
    "tier_prices": [],
    "custom_attributes": [{
        "attribute_code": "description",
        "value": "<p>Ideal for cold-weather training or work outdoors, the Chaz Hoodie promises superior warmth with every wear. Thick material blocks out the wind as ribbed cuffs and bottom band seal in body heat.</p>\n<p>&bull; Two-tone gray heather hoodie.<br />&bull; Drawstring-adjustable hood. <br />&bull; Machine wash/dry.</p>"
    }]
}, {
    "id": 83,
    "sku": "MH02",
    "name": "Teton Pullover Hoodie",
    "attribute_set_id": 9,
    "price": 0,
    "status": 1,
    "visibility": 4,
    "type_id": "configurable",
    "created_at": "2016-09-26 06:45:53",
    "updated_at": "2016-09-26 06:45:53",
    "extension_attributes": [],
    "product_links": [],
    "tier_prices": [],
    "custom_attributes": [{
        "attribute_code": "description",
        "value": "<p>This Teton Pullover Hoodie gives you more than laid-back style. It's equipped with moisture-wicking fabric to keep light and dry inside, especially in chilly-weather workouts. An elasticized hem lets you move about freely.</p>\n<p>&bull; Black pullover hoodie.<br />&bull; Soft, brushed interior. <br />&bull; Front hand pockets. <br />&bull; Machine wash/dry.</p>"
    }]
}, {
    "id": 99,
    "sku": "MH03",
    "name": "Bruno Compete Hoodie",
    "attribute_set_id": 9,
    "price": 0,
    "status": 1,
    "visibility": 4,
    "type_id": "configurable",
    "created_at": "2016-09-26 06:45:53",
    "updated_at": "2016-09-26 06:45:53",
    "extension_attributes": [],
    "product_links": [],
    "tier_prices": [],
    "custom_attributes": [{
        "attribute_code": "description",
        "value": "<p>Stay comfortable and stay in the race no matter what the weather's up to. The Bruno Compete Hoodie's water-repellent exterior shields you from the elements, while advanced fabric technology inside wicks moisture to keep you dry.</p>\n<p>&bull; Full zip black hoodie pullover. <br />&bull; Adjustable drawstring hood. <br />&bull; Ribbed cuffs/waistband. <br />&bull; Kangaroo pocket. <br />&bull; Machine wash/dry.</p>"
    }]
}, {
    "id": 115,
    "sku": "MH04",
    "name": "Frankie  Sweatshirt",
    "attribute_set_id": 9,
    "price": 0,
    "status": 1,
    "visibility": 4,
    "type_id": "configurable",
    "created_at": "2016-09-26 06:45:53",
    "updated_at": "2016-09-26 06:45:53",
    "extension_attributes": [],
    "product_links": [],
    "tier_prices": [],
    "custom_attributes": [{
        "attribute_code": "description",
        "value": "<p>The Frankie Sweatshirt is your best friend at long afternoon stadium stints or winter trailside campsites. The soft fleece fabric keeps you toasty as moisture-wicking technology kicks in when the sun comes out.</p>\n<p>&bull; Light green crewneck sweatshirt.<br />&bull; Hand pockets.<br />&bull; Relaxed fit.<br />&bull; Machine wash/dry.</p>"
    }]
}, {
    "id": 131,
    "sku": "MH05",
    "name": "Hollister Backyard Sweatshirt",
    "attribute_set_id": 9,
    "price": 0,
    "status": 1,
    "visibility": 4,
    "type_id": "configurable",
    "created_at": "2016-09-26 06:45:53",
    "updated_at": "2016-09-26 06:45:53",
    "extension_attributes": [],
    "product_links": [],
    "tier_prices": [],
    "custom_attributes": [{
        "attribute_code": "description",
        "value": "<p>Kick off your weekend in the Hollister Backyard Sweatshirt. Whether you're raking leaves or flipping burgers, this comfy layer blocks the bite of the crisp autumn air. Puffy thick from hood to hem, it traps heat against your core.</p>\n<p>&bull; Cream crewneck sweatshirt with navy sleeves/trim.<br />&bull; Relaxed fit. <br />&bull; Ribbed cuffs and hem. <br />&bull; Machine wash/dry.</p>"
    }]
}],
"search_criteria": {
    "filter_groups": [{
        "filters": [{
            "field": "type_id",
            "value": "configurable",
            "condition_type": "eq"
        }]
    }],
    "page_size": 5,
    "current_page": 1
},
"total_count": 147
}

for more attribute change type_id with the atteibute code and value of the attribute for example: searchCriteria[filterGroups][0][filters][0][field] color

searchCriteria[filterGroups][0][filters][0][value] red

searchCriteria[filterGroups][0][filters][0][conditionType] eq

  • How to display a real price without 0 ? – Jsparo30 Aug 20 '17 at 5:56
0

For displaying the price of the child product you have to customize the default Magento 2 product listing API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.