I need to change the response of Search Rest API in Magento 2.
Request:rest/V1/search?searchCriteria[requestName]=quick_search_container
&searchCriteria[filterGroups][0][filters][0][field]=search_term
&searchCriteria[filterGroups][0][filters][0][value]=t-shirt
&searchCriteria[filterGroups][1][filters][1][field]=sleeve_type
&searchCriteria[filterGroups][1][filters][1][value]=173
&searchCriteria[filterGroups][2][filters][2][field]=neck
&searchCriteria[filterGroups][2][filters][2][value]=105
Response:
"items": [
{
"id": 154,
"custom_attributes": [
{
"attribute_code": "score",
"value": "45.5335884094238300"
}
]
}
]
need to add more product information like product name, sku, type, images etc..,
"items": [
{
"id": 154,
"sku": "sample001",
"name": "sample product 1",
"type": "configurable",
"image_url": "http://magentohost/pub/media/catalog/product/s/s/1.png",
"custom_attributes": [
{
"attribute_code": "score",
"value": "45.5335884094238300"
}
]
}
]
but response have id and score only. How to add product information to search api response?
Best Answer
The beautiful thing about Magento is that you can take reference from the its core code. For answering the question I will took the example of the product API call to filter product from the "color" attribute code.
rest/all/V1/products-render-info? searchCriteria[filterGroups][0][filters][0][field]=color& searchCriteria[filterGroups][0][filters][0][value]=53& searchCriteria[filterGroups][0][filters][0][conditionType]=eq& searchCriteria[sortOrders][0][field]=size& searchCriteria[sortOrders][0][direction]=asc& storeId=1 ¤cyCode=usd
From your code I assume that this is custom search criteria. Try to build search criteria in this way and if you are using the Magento code this can be helpful to you.