I need to fetch all product details along with its stock status. I tried this API call
rest/default/V1/products?searchCriteria[pageSize]=100&searchCriteria[currentPage]=1
According to the documentation
https://developer.adobe.com/commerce/webapi/rest/quick-reference/
it should provide stock details inside the extension attributes section. But when I look at the response it won't give me the stock status. Can you please help me on this to retrieve product details along with it's stock statuses with this REST API call?
Solved! Go to Solution.
Hi @dulithsena0ae6 ,
I found below link while doing research on your query
https://github.com/magento/magento2/issues/22737
From there I got below solution
https://github.com/menacoders/Stock-Info-API-searchCriteria
According to above link /V1/products?searchCriteria does not include stock info
After install above extension you may find solution which you want
rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=quantity_and_stock_status&searchCriteria[filter_groups][0][filters][0][value]=2
Problem Solved? Accept as Solution!
Thanks
Hi @dulithsena0ae6 ,
I found below link while doing research on your query
https://github.com/magento/magento2/issues/22737
From there I got below solution
https://github.com/menacoders/Stock-Info-API-searchCriteria
According to above link /V1/products?searchCriteria does not include stock info
After install above extension you may find solution which you want
rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=quantity_and_stock_status&searchCriteria[filter_groups][0][filters][0][value]=2
Problem Solved? Accept as Solution!
Thanks
Hi @Ankit Jasani,
This is working for our development instance as we are able to upload these files. but if we need to fetch data from multiple demo instances where we can't upload these modules due to conflicts or something like that, this approach can't be used. I'm expecting to get this resolved from the API level.
Thanks,
Dulith
Hi @Ankit Jasani,
Yes able to use Graphql instead of REST API. If so how can we implement this Graphql API. IS there any guidance for this?
Thanks,
Dulith
Hi @dulithsena0ae6 ,
Please refer below
https://developer.adobe.com/commerce/webapi/graphql-api/#group-Operations-Queries
Thanks
Ankit
Hi @Ankit Jasani,
I will refer to this.
Thanks,
Dulith
Hi @dulithsena0ae6 ,
Also, do accept the solution if earlier or current answer worked for you so that anyone else also facing something similar can directly go to the right response.
Hi @Ankit Jasani,
I tried this curl request to fetch data from graphql API,
curl --location 'https://<domain>/graphql' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <token>' \ --header 'Cookie: PHPSESSID=ddlgqjuss0grfqfde6rjqrm9vs; private_content_version=9c6fa6d9869669a64e30b2f2d83ed637' \ --data '{ "query": "query GetProducts($search: String, $pageSize: Int, $currentPage: Int) { products(search: $search, pageSize: $pageSize, currentPage: $currentPage) { items { id name sku } total_count } }", "variables": { "search": "", "pageSize": 10, "currentPage": 1 } }'
but I get an empty array as below. How can I resolve this?
{ "data": { "products": { "items": [], "total_count": 0 } } }
Hi @dulithsena0ae6 ,
curl --location -g --request POST '{{host_url}}graphql' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"query GetProducts($search: String, $pageSize: Int, $currentPage: Int) { products(search: $search, pageSize: $pageSize, currentPage: $currentPage) { items { id name sku } total_count } }","variables":{"search":"","pageSize":10,"currentPage":1}}'
is working fine for me and I can see results.