Magento – Getting full image url for products via REST API

http-requestmagento-1.9magento-enterprisemagento2rest

After accessing the Rest API (http://192.168.1.180/magento/index.php/rest/V1/products/SKU) to get the product details, the response is something like this:

{ "attribute_code": "image", "value": "/6/4/64275-152378-large.jpg" }, { "attribute_code": "small_image", "value": "/6/4/64275-152378-large.jpg" }, { "attribute_code": "thumbnail", "value": "/6/4/64275-152378-large.jpg" }

What should be the base url/prefix for the jpg in the attribute_code keys ?

Best Answer

In Magento 2x the product image urls are all relative. It's possible some extension or usage of CDN could change the base path. You can call the the V1/store/StoreConfigs api and use the baseMediaUrl value to get the full path.