Product search is a very critical part of any e-commerce website. When the customer needs a specific product, he searches in this quick and advanced search bar itself.
There are two REST APIs inside Magento, one for quick search and one for advanced search.
Under Quick Search, the customer enters a particular name or SKU, ie, enters the search term.
And then after that, it hits and as soon as there is a matching product with that particular name, we will get that product as a response.
If the customer wants the product to be visible in the middle of a particular range, then for that we have to use the advanced search container which is given below endpoint.
Magento 2 Quick and Advanced Search REST API
Two search containers are given below of Magento 2 Quick and Advanced Search REST API.
Quick Searches REST API in Magento 2
When we open the Magento 2 website, the normal product catalog search that appears is called the quick search container.
If we want to get the data of that quick search container through Rest API in Magento 2, then for that I am mentioning the endpoints below.
You can get the data by adding content-type application JSON and method entering the authorized bearer token in the header.
Endpoint:
https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=quick_search_container&searchCriteria[filter_groups][0][filters][0][field]=search_term&searchCriteria[filter_groups][0][filters][0][value]=iphone
Method: GET
Header:
- Authorization: Bearer <admin_token>
- Content-Type: application/json
Response:
{ "items": [ { "id": 14, "custom_attributes": [ { "attribute_code": "score", "value": "116.2562599182128900" } ] }, { "id": 8, "custom_attributes": [ { "attribute_code": "score", "value": "116.2562599182128900" } ] }, { "id": 4, "custom_attributes": [ { "attribute_code": "score", "value": "116.2562599182128900" } ] }, { "id": 1, "custom_attributes": [ { "attribute_code": "score", "value": "116.2562599182128900" } ] }, { "id": 2046, "custom_attributes": [ { "attribute_code": "score", "value": "103.3388977050781200" } ] }, { "id": 1722, "custom_attributes": [ { "attribute_code": "score", "value": "103.3388977050781200" } ] }, { "id": 688, "custom_attributes": [ { "attribute_code": "score", "value": "38.7520866394043000" } ] }, { "id": 23, "custom_attributes": [ { "attribute_code": "score", "value": "6.4586811065673830" } ] }, { "id": 15, "custom_attributes": [ { "attribute_code": "score", "value": "6.4586811065673830" } ] }, { "id": 3, "custom_attributes": [ { "attribute_code": "score", "value": "6.4586811065673830" } ] } ], "aggregations": { "buckets": [ { "name": "category_bucket", "values": [ { "value": "3", "metrics": [ "3", "7" ] }, { "value": "4", "metrics": [ "4", "5" ] }, { "value": "5", "metrics": [ "5", "2" ] }, { "value": "7", "metrics": [ "7", "2" ] }, { "value": "8", "metrics": [ "8", "2" ] }, { "value": "12", "metrics": [ "12", "1" ] }, { "value": "17", "metrics": [ "17", "1" ] }, { "value": "21", "metrics": [ "21", "1" ] }, { "value": "22", "metrics": [ "22", "1" ] }, { "value": "26", "metrics": [ "26", "1" ] }, { "value": "28", "metrics": [ "28", "1" ] }, { "value": "34", "metrics": [ "34", "2" ] } ] } ], "bucket_names": [ "category_bucket" ] }, "search_criteria": { "request_name": "quick_search_container", "filter_groups": [ { "filters": [ { "field": "search_term", "value": "bag", "condition_type": "eq" } ] } ] }, "total_count": 10 }
Product Advanced Search Container REST API
By using this advanced search container REST API, you can do an advanced search of the product of the Magento store.
You can set the minimum price and set a maximum price.
Whatever product is in between the minimum price to the maximum price, you will see it as a response.
For example, if you have set the minimum price as 200 and the maximum price is 500, then all the products in the range between 200 to 500 will be shown to you as a response through this rest API
Endpoint
https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=advanced_search_container&searchCriteria[filter_groups][0][filters][0][field]=price.from&searchCriteria[filter_groups][0][filters][0][value]=200&searchCriteria[filter_groups][0][filters][1][field]=price.to&searchCriteria[filter_groups][0][filters][1][value]=500
Method: GET
Header:
- Authorization: Bearer <admin_token>
- Content-Type: application/json
Body: Not required
Advanced Search Container PRAM in REST API
Response:
{ "items": [], "aggregations": { "buckets": [], "bucket_names": [] }, "search_criteria": { "request_name": "advanced_search_container", "filter_groups": [ { "filters": [ { "field": "price.from", "value": "200", "condition_type": "eq" }, { "field": "price.to", "value": "500", "condition_type": "eq" } ] } ] }, "total_count": 0 }
Read more: Search REST API List: Magento 2 API List of Product Search Endpoint