1

I want to use magento2 rest api of products to get list of details of products based on some criteria. For example -

http://localhost:8080/magento/index.php/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=updated_at&searchCriteria[filter_groups][0][filters][0][value]=2016-06-01 10:38:52&searchCriteria[filter_groups][0][filters][0][condition_type]=gteq&fields=items[id,sku,name,price,created_at,updated_at,custom_attributes]

Above url get list of products whose updated date is after or equal to 2016-06-01 10:38:52. Here is the small part of sample output -

"items": [
    {
      "id": 54,
      "sku": "MH01-XS-Orange",
      "name": "Chaz Kangeroo Hoodie-XS-Orange",
      "price": 52,
      "created_at": "2016-06-01 10:38:52",
      "updated_at": "2016-06-01 10:38:52",
      "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>"
        },
        {
          "attribute_code": "image",
          "value": "/m/h/mh01-orange_main.jpg"
        },
        {
          "attribute_code": "small_image",
          "value": "/m/h/mh01-orange_main.jpg"
        },
        {
          "attribute_code": "thumbnail",
          "value": "/m/h/mh01-orange_main.jpg"
        },
        {
          "attribute_code": "color",
          "value": "56"
        },
        {
          "attribute_code": "options_container",
          "value": "container2"
        },
        {
          "attribute_code": "required_options",
          "value": "0"
        },
        {
          "attribute_code": "has_options",
          "value": "0"
        },
        {
          "attribute_code": "msrp_display_actual_price_type",
          "value": "0"
        },
        {
          "attribute_code": "url_key",
          "value": "chaz-kangeroo-hoodie-xs-orange"
        },
        {
          "attribute_code": "tax_class_id",
          "value": "2"
        },
        {
          "attribute_code": "size",
          "value": "167"
        }
      ]
    },

I want to filter the output by some attribute code. for example i want to get Products with particular color , products with particular materials.

How can i do this?

0

You can use url like below change with your attribute code and it's value

http://mcs.com/beta/pmagento2/index.php/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=name&searchCriteria[filter_groups][0][filters][0][value]=First%20Product%20test%20work&searchCriteria[filter_groups][0][filters][0][condition_type]=&searchCriteria[filter_groups][0][filters][0][field]=price&searchCriteria[filter_groups][0][filters][0][value]=10&fields=items[id,sku,name,price,created_at,updated_at,custom_attributes]

4
  • can we use multiple filters in this url, for example products of price =52 and color =red Jun 20 '16 at 9:52
  • I have updated answer check it Jun 20 '16 at 10:08
  • what is First%20Product%20test%20work Jun 21 '16 at 4:26
  • This is product name "FIrst Product test Work" Jun 22 '16 at 5:26

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.