magento2: "/rest/V1/products?searchCriteria" API endpoint" does not return information about stock in the "extension_attributes" section
Preconditions
- Magento 2.2.7 community Edition.
- REST API filtering products using rest/V1/products?searchCriteria
Steps to reproduce
- we have disable showing out of stock products from Magento Dashboard (Stores > Configuration > Catalog > Inventory > Display Out of stock products No)
- 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
- The response contains infromation about stock per each product in the “extension_attributes” section
Actual result
- 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)
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 👍
@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:
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
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?
@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.
Can you find the StockRegistry.php class?