2

I use this API to fetch the visible products using the filter:

http://192.168.1.180/magento/index.php/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=name&searchCriteria[filter_groups][0][filters][0][value]=%Nike%&searchCriteria[filter_groups][0][filters][0][condition_type]=like

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.

Alex Paliarush
13.8k5 gold badges53 silver badges57 bronze badges
asked Dec 10, 2015 at 12:57

1 Answer 1

0

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>
answered Dec 10, 2015 at 15:16
8

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.