How do we get the url to thumbnail image of of a product through rest API.
/V1/products/{sku}/media
would get us the relative url such as "/m/b/mb01-blue-0.jpg"
and the image url would be baseurl/catalog/product/m/b/mb01-blue-0.jpg
This works fine. But how do we get the thumbnail which usually resides in the cache folder.
Best Answer
If you need the complete path of the thumbnail image with Magento 2 cache system through API, you can create your custom API based on the native ProductRepository class.
Create a new module. (explained in other posts)
Create a etc/webapi.xml file :
Create a etc/di.xml file :
Create your interface Api\ProductRepositoryInterface.php :
Create your model Model\ProductRepository.php :
Access
Go to
/rest/V1/custom/products/{sku}
You should retrieve the thumbnail image with the image frontend URL cached :
Comments :
The third parameter of the function startEnvironmentEmulation is used to force the use of frontend area if you are already on the same storeId. (usefull for API area)
I do not test this custom API, you may adapt the code but the logic is correct but I already tested the part to retrieve the image URL in other custom API.
This workaround avoid you to have this kind of errors :