I'm working on native mobile application and want to display product after customer selected a category. I am able to get list of the product by category in rest request but that list don't have much details about the product.
Request : http://localhost/magento2/index.php/rest/V1/categories/24/products
(24 is category ID)
Response : [{"sku":"WH01","position":1,"category_id":"24"},...]
Earlier in Magento 1.9
product list was something like
{ 2: { entity_id: "2" type_id: "simple" sku: "Levis Bagpack" description: "Bagpack" short_description: "Bagpack" meta_keyword: null name: "Levis Bagpack" meta_title: null meta_description: null regular_price_with_tax: 45 regular_price_without_tax: 45 final_price_with_tax: 45 final_price_without_tax: 45 is_saleable: true image_url: "http://172.16.8.24:8080/magento/media/catalog/product/cache/0/image/9df78eab33525d08d6e5fb8d27136e95/images/catalog/product/placeholder/image.jpg" }-
What should I do to get more info about product so I can show image and other things in mobile app ?
Best Answer
Maybe you can try the GET /V1/products/:sku REST API to get all the details (https://github.com/magento/magento2/blob/develop/app/code/Magento/Catalog/etc/webapi.xml#l36)
The returned value will be representation of \Magento\Catalog\Api\Data\ProductInterface (including the additional attributes) https://github.com/magento/magento2/blob/develop/app/code/Magento/Catalog/Api/Data/ProductInterface.php
Check \Magento\Catalog\Api\ProductRepositoryInterface::get which services the GET /V1/products/:sku REST API.
You can make multiple requests for all product SKUs.
OR
You can use the search API to fetch the entire list in a single request based on your criteria:
ex: http://localhost/magento2/index.php/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=simple&searchCriteria[filter_groups][0][filters][1][field]=sku&searchCriteria[filter_groups][0][filters][1][value]=Simple2&searchCriteria[filter_groups][0][filters][0][condition_type]=eq&searchCriteria[current_page]=1&searchCriteria[page_size]=2
In this case products with SKUs - simple and Simple2 are being searched.