Magento product apis short and full

return only name field in this api in Magento 2 "/rest/all/V1/products?fields=items[name,price]&storeId=0&currencyCode=GBP&searchCriteria%5BcurrentPage%5D=1&searchCriteria%5BpageSize%5D=10"

Sure! To return only the name field in the Magento 2 API request you provided, you can modify the fields parameter as follows:

https://example.com/rest/all/V1/products?fields=items[name]&storeId=0&currencyCode=GBP&searchCriteria%5BcurrentPage%5D=1&searchCriteria%5BpageSize%5D=10

also return only specific attributes like where attribute_code is "imgtype",

To return only the name attribute and a specific custom attribute where attribute_code is "imgtype" for all items in the response from the Magento 2 API request you provided, you can modify the fields parameter as follows:

https://example.com/rest/all/V1/products?fields=items[name,custom_attributes[attribute_code,value]]&storeId=0&currencyCode=GBP&searchCriteria%5BcurrentPage%5D=1&searchCriteria%5BpageSize%5D=1&searchCriteria[filter_groups][0][filters][0][field]=attribute_code&searchCriteria[filter_groups][0][filters][0][value]=imgtype

We added the custom_attributes[attribute_code,value] parameter to the fields parameter to specify that we want to include the attribute_code and value attributes for all custom attributes in each product object. Then, we added searchCriteria parameters to filter the products by the imgtype attribute.

Note that we left the name attribute in the fields parameter to include it in the response as well. You can remove it if you don't need it.

also return custom_attribute "description" and "shipping_method"

To return only the name attribute and the custom attributes description and shipping_method for all items in the response from the Magento 2 API request you provided, you can modify the fields parameter as follows:

https://example.com/rest/all/V1/products?fields=items[name,custom_attributes[attribute_code,value]]&storeId=0&currencyCode=GBP&searchCriteria%5BcurrentPage%5D=1&searchCriteria%5BpageSize%5D=1&searchCriteria[filter_groups][0][filters][0][field]=attribute_code&searchCriteria[filter_groups][0][filters][0][value]=imgtype&searchCriteria[filter_groups][1][filters][0][field]=attribute_code&searchCriteria[filter_groups][1][filters][0][value]=description&searchCriteria[filter_groups][2][filters][0][field]=attribute_code&searchCriteria[filter_groups][2][filters][0][value]=shipping_method

return only name of all items response in magetno 2 "/rest/all/V1/products?&storeId=0¤cyCode=GBP&searchCriteria%5BcurrentPage%5D=1&searchCriteria%5BpageSize%5D=1`;" now return custom_attributes 'description' and first media_gallery_entries

To return only the name attribute and the description custom attribute and the first media_gallery_entries attribute for all items in the response from the Magento 2 API request you provided, you can modify the fields parameter as follows:

https://example.com/rest/all/V1/products?fields=items[name,custom_attributes[attribute_code,value],media_gallery_entries[file]]&storeId=0&currencyCode=GBP&searchCriteria%5BcurrentPage%5D=1&searchCriteria%5BpageSize%5D=10

fetch all product 20 item per page with search_criteria,total_count

const url = `${process.env.NEXT_PUBLIC_MAGENTO_BASE_URL}/rest/all/V1/products?fields=items[name,sku,custom_attributes[attribute_code,value],media_gallery_entries[file]],search_criteria,total_count&storeId=0&currencyCode=GBP&searchCriteria%5BcurrentPage%5D=1&searchCriteria%5BpageSize%5D=6`;

Did you find this article valuable?

Support Mandeep Singh Blog by becoming a sponsor. Any amount is appreciated!