I use this API to fetch the visible products using the filter:
Is there a better way to search from the REST API ? This URL will become really big in case of increased search terms, for instance, If I query for 10 SKU names.
1 Answer 1
It is better to use search API (rest/V1/search), is faster because based on index tables, and then load full information about products returned from search using product repository (rest/V1/products). 
You would have a list of product IDs returned by search API and in filter can be used when creating search criteria for rest/V1/products, this will make URL shorter. However, request URL for Search API would still be long.
There is no way to reduce URL length except for introducing alternative POST or PUT endpoing in your module (VendorName/ModuleName/etc/webapi.xml). Then you should be able to specify filters in request body.
<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
 <route url="/V1/searchProducts" method="POST">
 <service class="Magento\Catalog\Api\ProductRepositoryInterface" method="getList"/>
 <resources>
 <resource ref="anonymous" />
 </resources>
 </route>
</routes>
- 
 can you help out with the modification in webapi.xml.. any tutorial link ?devdoe– devdoe2015年12月11日 12:22:44 +00:00Commented Dec 11, 2015 at 12:22
- 
 Take a look at official docs devdocs.magento.com/guides/v2.0//extension-dev-guide/…Alex Paliarush– Alex Paliarush2015年12月11日 13:46:17 +00:00Commented Dec 11, 2015 at 13:46
- 
 Ok.. and also the 192.168.1.180/magento/index.php/rest/V1/search?searchCriteria is giving error. I think, the search criteria parameter should be same across all the requests, but it is giving an error.devdoe– devdoe2015年12月13日 08:31:25 +00:00Commented Dec 13, 2015 at 8:31
- 
 Field name should besearch_term, see php example here magento.stackexchange.com/a/90607/697 , also try to check out documentation for search API on Magento dev docsAlex Paliarush– Alex Paliarush2015年12月13日 09:20:54 +00:00Commented Dec 13, 2015 at 9:20
- 
 192.168.1.180/magento/index.php/rest/V1/…. this still gives errordevdoe– devdoe2015年12月14日 06:38:00 +00:00Commented Dec 14, 2015 at 6:38
Explore related questions
See similar questions with these tags.