magento2: "/rest/V1/products?searchCriteria" API endpoint" does not return information about stock in the "extension_attributes" section

Preconditions

  1. Magento 2.2.7 community Edition.
  2. REST API filtering products using rest/V1/products?searchCriteria

Steps to reproduce

  1. we have disable showing out of stock products from Magento Dashboard (Stores > Configuration > Catalog > Inventory > Display Out of stock products No)
  2. we using this api to filtering product /rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=category_id&searchCriteria[filter_groups][0][filters][0][value]=35&searchCriteria[current_page]=1&searchCriteria[page_size]=40

Expected result

  1. The response contains infromation about stock per each product in the “extension_attributes” section

Actual result

  1. There is no information about stock status per product in “extension_attributes” and no possibility to understand is it available on Storefront

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 24 (2 by maintainers)

Most upvoted comments

Hi @scne i have uploaded the module, get it from here https://github.com/menacoders/Stock-Info-API-searchCriteria

and let me know if you need anything else 👍

Hi @scne i have uploaded the module, get it from here https://github.com/menacoders/Stock-Info-API-searchCriteria and let me know if you need anything else

Thank you. One question, how can we filter out these out-of-stock products from the API result?

@titechnologies you are welcome.

you mean, you only want to return the in_stock products ? if that what you want… you could use this api

rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=quantity_and_stock_status&searchCriteria[filter_groups][0][filters][0][value]=2

just add the quantity_and_stock_status filter so it’s will return the in_stock products instock value = 2 outofstock value = 1

Hello @MagentoAr

Thank you for the report!

We investigated this issue and as results:

  1. Initially “/rest/V1/products?searchCriteria” API endpoint was developed for wider use and it should not returns only In Stock products by design. Even if you set “Stores > Configuration > Catalog > Inventory > Display Out of stock products No” the product will be available by direct URL on Storefront. I suppose it needs for SEO purposes and indexation by other systems. And because of that issue cannot be confirmed and proved for fix with described use case

  2. But the real bug is “/rest/V1/products?searchCriteria” API endpoint" does not return information about stock in the “extension_attributes” section.

so, I updated Issue title and description with this information Are you ok with this?

any news about this issue?

@scne it’s still not fixed in any version i have built a module to solve this issue, i’ll share it with you these days.

@vteofilo thank you but i really don’t know where to put your code.

Can you find the StockRegistry.php class?