Magento – How to get qty of a product using rest api

magento-2.1magento2restrest api

I want to get product info including the product qty how can i achieve it.

Currently i am using

rest/default/V1/products?searchCriteria

To get all the product but it is missing qty attribute in it.

Here is the result

   [0] => stdClass Object
      (
        [id] => 346
        [sku] => WATCH
        [name] => WATCH
        [attribute_set_id] => 4
        [price] => 3
        [status] => 1
        [visibility] => 4
        [type_id] => simple
        [created_at] => 2018-06-03 05:36:33
        [updated_at] => 2018-06-03 05:36:33
        [weight] => 1
        [product_links] => Array
            (
            )

        [tier_prices] => Array
            (
            )

        [custom_attributes] => Array
            (
                [0] => stdClass Object
                    (
                        [attribute_code] => meta_title
                        [value] => WATCH
                    )

                [1] => stdClass Object
                    (
                        [attribute_code] => meta_keyword
                        [value] => WATCH
                    )

                [2] => stdClass Object
                    (
                        [attribute_code] => meta_description
                        [value] => WATCH 
                    )

                [3] => stdClass Object
                    (
                        [attribute_code] => image
                        [value] => /p/i/pinking_swatch_sq_dia_beige_1.png
                    )

                [4] => stdClass Object
                    (
                        [attribute_code] => small_image
                        [value] => /p/i/pinking_swatch_sq_dia_beige_1.png
                    )

                [5] => stdClass Object
                    (
                        [attribute_code] => thumbnail
                        [value] => /p/i/pinking_swatch_sq_dia_beige_1.png
                    )

                [6] => stdClass Object
                    (
                        [attribute_code] => category_ids
                        [value] => Array
                            (
                                [0] => 4
                                [1] => 61
                            )

                    )

                [7] => stdClass Object
                    (
                        [attribute_code] => options_container
                        [value] => container2
                    )

                [8] => stdClass Object
                    (
                        [attribute_code] => required_options
                        [value] => 0
                    )

                [9] => stdClass Object
                    (
                        [attribute_code] => has_options
                        [value] => 0
                    )

                [10] => stdClass Object
                    (
                        [attribute_code] => url_key
                        [value] => watch
                    )

                [11] => stdClass Object
                    (
                        [attribute_code] => gift_message_available
                        [value] => 2
                    )

                [12] => stdClass Object
                    (
                        [attribute_code] => swatch_image
                        [value] => /p/i/pinking_swatch_sq_dia_beige_1.png
                    )

                [13] => stdClass Object
                    (
                        [attribute_code] => tax_class_id
                        [value] => 2
                    )

            )

    )

Best Answer

Try using /V1/stockItems/:productSku

For more details, you can go through https://devdocs.magento.com/guides/v2.0/rest/list.html#cataloginventory

Related Topic