I am sharing below a list of the product search rest API of how to filter and search any product inside Magento 2.
With the help of this, you will be able to access all the lists of APIs on a single platform.
Within this, you can also search for the product on the basis of the ID of any category.
Whether it is to do an advanced search, you can search and filter the product using the API by all means.
You can also search products on the basis of price i.e. from low price to max price.
You can search the product by product name.
Search by ID using rest API also available in this list.
Product Search REST API for Search And Filter
There are many ways to filter a product in Magento, one of them is you can filter a product is by category ID.
So using this REST API, you can field all products of any category ID.
Or if you want to filter the product by category name then you can also use this rest API in Magento 2.
Endpoint:
https://wishusucess.com/rest/V1/categories/2/products
Method: GET
Header:
- Authorization: Bearer <admin_token>
- Content-Type: application/json
Example:
Response:
[ { "sku": "24-MB01", "position": 0, "category_id": "2" }, { "sku": "24-MB04", "position": 0, "category_id": "2" }, { "sku": "WSH12", "position": 0, "category_id": "2" } ]
Read more: Elasticsearch: How to Install Elasticsearch in Ubuntu 18.04
Quick Searches REST API in Magento 2
Below is the Quick search container Magento 2 REST API that will help you to search the product quickly.
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
Example:
Read more: Search Container REST API
Advanced Search Container Magento 2 REST API
Advanced_search_container
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
Example:
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 Container REST API
Gets Products Where The SKU Search in Magento 2 REST API
Looking for API to search catalog product inside magento2 rising rest API then you can use below endpoint.
This API is used to perform product searches based on SKU inside the magento2 store.
In order to do an SKU-based products search, you have to hit the below Magento 2 rest API endpoint, after hitting it, whatever content matches it, you will get it as a response.
Endpoint
https://wishusucess.com/rest/default/V1/search?searchCriteria[requestName]=advanced_search_container&searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=24-MB01&searchCriteria[filter_groups][0][filters][0][condition_type]=like
Method: GET
Header:
- Authorization: Bearer <admin_token>
- Contnet Type: application/json
Example:
Response:
{ "items": [ { "id": 1, "custom_attributes": [ { "attribute_code": "score", "value": "0.0000000000000000" } ] } ], "aggregations": { "buckets": [], "bucket_names": [] }, "search_criteria": { "request_name": "advanced_search_container", "filter_groups": [ { "filters": [ { "field": "sku", "value": "24-MB01", "condition_type": "like" } ] } ] }, "total_count": 1 }
Product Filter Using Price And SKU in Magento 2 REST API
To search catalog product inside Magento 2 store if we want to add some condition like catalog product search based on SKU and price range both together.
So for that Magento 2 has a separate rest API endpoint we have to hit that endpoint.
And also we can decide the price range according to our need and SKU add both have to be added together as add param.
Endpoint:
https://wishusucess.com/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=Coquefhoih72389&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][1][field]=sku&searchCriteria[filter_groups][0][filters][1][value]=Coque12345&searchCriteria[filter_groups][0][filters][1][condition_type]=like&searchCriteria[filter_groups][1][filters][0][field]=price&searchCriteria[filter_groups][1][filters][0][value]=400&searchCriteria[filter_groups][1][filters][0][condition_type]=from&searchCriteria[filter_groups][2][filters][0][field]=price&searchCriteria[filter_groups][2][filters][0][value]=600&searchCriteria[filter_groups][2][filters][0][condition_type]=to
Method: GET
Header:
- Authorization: Bearer <admin_token>
- Contnet Type: application/json
Example:
Response:
{ "items": [], "search_criteria": { "filter_groups": [ { "filters": [ { "field": "sku", "value": "Coquefhoih72389", "condition_type": "like" }, { "field": "sku", "value": "Coque12345", "condition_type": "like" } ] }, { "filters": [ { "field": "price", "value": "400", "condition_type": "from" } ] }, { "filters": [ { "field": "price", "value": "600", "condition_type": "to" } ] } ] }, "total_count": 0 }
A Simple Search Using an in Conditions Type
For logical OR search, one has to hit logical OR search rest API in Magento website i.e. inside normal condition search rest API we will add any product name or whatever you want to search string as a string.
Then after that when you hit the endpoint then the response you get after that will be the response of your conditional search reply.
Endpoint:
https://wishusucess.com/rest/default/V1/products?searchCriteria[filter_groups][0][filters][0][field]=name&searchCriteria[filter_groups][0][filters][0][value]=Coque Carbone et Effet Brossé Silicone à Coins Renforcés&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][1][field]=name&searchCriteria[filter_groups][0][filters][1][value]=Accessoires Apple iPhone&searchCriteria[filter_groups][0][filters][1][condition_type]=like
Method: GET
Header:
- Authorization: Bearer <admin_token>
- Contnet Type: application/json
Example:
Response:
{ "items": [], "search_criteria": { "filter_groups": [ { "filters": [ { "field": "name", "value": "Coque Carbone et Effet Brossé Silicone à Coins Renforcés", "condition_type": "like" }, { "field": "name", "value": "Accessoires Bag", "condition_type": "like" } ] } ] }, "total_count": 0 }
Logical and Condition Search REST API Magento 2
For logical and conditional search we have to hit REST API of the Magento 2 website.
Whatever condition we have to send in this, we can decide and we can impose the logical conditions.
As its key value, we can add both SKU and Price together, and as soon as hit we will get the data as a response.
Endpoint:
https://wishusucess.com/rest/default/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=Accessoires1278&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][1][filters][0][field]=price&searchCriteria[filter_groups][1][filters][0][value]=2500&searchCriteria[filter_groups][1][filters][0][condition_type]=lt
Method: GET
Header:
- Authorization: Bearer <admin_token>
- Contnet Type: application/json
Example:
Response:
{ "items": [], "search_criteria": { "filter_groups": [ { "filters": [ { "field": "sku", "value": "MS", "condition_type": "like" } ] }, { "filters": [ { "field": "price", "value": "2500", "condition_type": "lt" } ] } ] }, "total_count": 0 }
Magento 2 Logical AND and OR Search REST API
In this logical and conditional search, you have to send SKU along with price range can also apply like a price from to price to price.
All the products available in this range in between, you will get the data in the form of a response.
Endpoint:
https://wishusucess.com/rest/default/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku&searchCriteria[filter_groups][0][filters][0][value]=Accessoires1278&searchCriteria[filter_groups][0][filters][0][condition_type]=like&searchCriteria[filter_groups][0][filters][1][field]=sku&searchCriteria[filter_groups][0][filters][1][value]=Coquefhoih72389&searchCriteria[filter_groups][0][filters][1][condition_type]=like&searchCriteria[filter_groups][1][filters][0][field]=price&searchCriteria[filter_groups][1][filters][0][value]=200&searchCriteria[filter_groups][1][filters][0][condition_type]=from&searchCriteria[filter_groups][2][filters][0][field]=price&searchCriteria[filter_groups][2][filters][0][value]=600&searchCriteria[filter_groups][2][filters][0][condition_type]=to
Method: GET
Header:
- Authorization: Bearer <admin_token>
- Contnet Type: application/json
Example:
Response:
{ "items": [ { "id": 1, "sku": "24-MB01", "name": "Joust Duffle Bag", "attribute_set_id": 15, "price": 34, "status": 1, "visibility": 4, "type_id": "simple", "created_at": "2022-01-24 18:19:43", "updated_at": "2022-01-24 18:19:43", "extension_attributes": { "website_ids": [ 1 ], "category_links": [ { "position": 0, "category_id": "3" }, { "position": 0, "category_id": "4" } ] }, "product_links": [ { "sku": "24-MB01", "link_type": "crosssell", "linked_product_sku": "24-UG01", "linked_product_type": "simple", "position": 3 }, { "sku": "24-MB01", "link_type": "crosssell", "linked_product_sku": "24-WG083-blue", "linked_product_type": "simple", "position": 2 }, { "sku": "24-MB01", "link_type": "crosssell", "linked_product_sku": "24-WG086", "linked_product_type": "simple", "position": 1 }, { "sku": "24-MB01", "link_type": "crosssell", "linked_product_sku": "24-WG085_Group", "linked_product_type": "grouped", "position": 4 }, { "sku": "24-MB01", "link_type": "upsell", "linked_product_sku": "24-MB03", "linked_product_type": "simple", "position": 2 }, { "sku": "24-MB01", "link_type": "upsell", "linked_product_sku": "24-MB05", "linked_product_type": "simple", "position": 3 }, { "sku": "24-MB01", "link_type": "upsell", "linked_product_sku": "24-MB06", "linked_product_type": "simple", "position": 4 }, { "sku": "24-MB01", "link_type": "upsell", "linked_product_sku": "24-MB02", "linked_product_type": "simple", "position": 1 }, { "sku": "24-MB01", "link_type": "upsell", "linked_product_sku": "24-UB02", "linked_product_type": "simple", "position": 5 }, { "sku": "24-MB01", "link_type": "upsell", "linked_product_sku": "24-WB03", "linked_product_type": "simple", "position": 6 }, { "sku": "24-MB01", "link_type": "upsell", "linked_product_sku": "24-WB07", "linked_product_type": "simple", "position": 8 }, { "sku": "24-MB01", "link_type": "upsell", "linked_product_sku": "24-WB04", "linked_product_type": "simple", "position": 7 } ], "options": [], "media_gallery_entries": [ { "id": 1, "media_type": "image", "label": "Image", "position": 1, "disabled": false, "types": [ "image", "small_image", "thumbnail" ], "file": "/m/b/mb01-blue-0.jpg" } ], "tier_prices": [], "custom_attributes": [ { "attribute_code": "image", "value": "/m/b/mb01-blue-0.jpg" }, { "attribute_code": "small_image", "value": "/m/b/mb01-blue-0.jpg" }, { "attribute_code": "thumbnail", "value": "/m/b/mb01-blue-0.jpg" }, { "attribute_code": "url_key", "value": "joust-duffle-bag" }, { "attribute_code": "required_options", "value": "0" }, { "attribute_code": "has_options", "value": "0" }, { "attribute_code": "category_ids", "value": [ "3", "4" ] }, { "attribute_code": "description", "value": "<p>The sporty Joust Duffle Bag can't be beat - not in the gym, not on the luggage carousel, not anywhere. Big enough to haul a basketball or soccer ball and some sneakers with plenty of room to spare, it's ideal for athletes with places to go.<p>\n<ul>\n<li>Dual top handles.</li>\n<li>Adjustable shoulder strap.</li>\n<li>Full-length zipper.</li>\n<li>L 29\" x W 13\" x H 11\".</li>\n</ul>" } ] } ], "search_criteria": { "filter_groups": [ { "filters": [ { "field": "sku", "value": "Accessoires1278", "condition_type": "like" }, { "field": "sku", "value": "24-MB01", "condition_type": "like" } ] }, { "filters": [ { "field": "price", "value": "30", "condition_type": "from" } ] }, { "filters": [ { "field": "price", "value": "600", "condition_type": "to" } ] } ] }, "total_count": 1 }
You can get all types of search data on the Magento website by changing a little bit in this way.
Now be it price filter, category search, product name search, all types of data can be accessed using this REST API in Magento 2.
Now despite this, if you need any help, then you can contact us, we will try our best to help you.
Thank you!!