FroheZukunft Posted June 19 Share Posted June 19 Hello, i am able to pull all product infos via the webservice api out of the shop. However, I don't succeed to get the product's images frontend url. I only get the raw image data via /api/images/products/. Is there any way to get the frontend urls of the product images? Something like https://my-shop.com/1-large_default/demo-artikel.jpg? Thank you in advance! Best Alex 1 Link to comment Share on other sites More sharing options...
Prestashop Addict Posted June 20 Share Posted June 20 Let's have a look in documentation Link to comment Share on other sites More sharing options...
Simon B. Posted June 20 Share Posted June 20 (edited) @Prestashop Addict unfortunately this documentation does not explain how to get the public URL of images. /api/images/* require the authentication token. For information the same question still remains unanswered since 2020: Edited June 20 by Simon B. (see edit history) Link to comment Share on other sites More sharing options...
Prestashop Addict Posted June 21 Share Posted June 21 I think you can construct the url with the link_rewrite of the product, something like, not universal but should work $uri = 'https://www.domai.ext/' . $id_productImage . '-large_default/' . $link_rewrite .'.jpg' Link to comment Share on other sites More sharing options...
FroheZukunft Posted June 21 Author Share Posted June 21 Thank you, that should do the trick. Best Alex Link to comment Share on other sites More sharing options...
Simon B. Posted June 21 Share Posted June 21 2 hours ago, Prestashop Addict said: I think you can construct the url with the link_rewrite of the product, something like, not universal but should work $uri = 'https://www.domai.ext/' . $id_productImage . '-large_default/' . $link_rewrite .'.jpg' This solution works when writing PHP code inside prestashop. The good news is that the filename is ignored ($link_rewrite), so the image ID loaded from /api/images/products or /api/products is almost enough to build the public URL: https://www.domai.ext/{imageId}-large_default/whatever.jpg returns the correct image. The only guess is that the image type is jpg. Replacing whatever.jpg by whatever.png does not work. Link to comment Share on other sites More sharing options...
Prestashop Addict Posted June 24 Share Posted June 24 You should be able to retrieve link_rewrite with API in product // Initialize the PrestaShop webservice $webService = new PrestaShopWebservice($shopUrl, $apiKey, false); // Retrieve product data (replace 1 with your product ID) $opt = array('resource' => 'products', 'id' => 1); $xml = $webService->get($opt); // Access product details $product = $xml->children()->children(); // Get the link_rewrite field for the product $linkRewrite = (string)$product->link_rewrite; // Get the ID of the default image (cover image) $defaultImageId = (string)$product->associations->images->image[0]->id; // Construct the image URL $imageUrl = 'https://www.domai.ext/' . $defaultImageId . '-large_default/' . $linkRewrite .'.jpg'; and for file type you can use something like (poor performance 😞 but woks ) // Possible file extensions $extensions = ['jpg', 'png', 'jpeg', 'webp']; // Function to check if a URL exists function url_exists($url) { $headers = get_headers($url); return stripos($headers[0], "200 OK") ? true : false; } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now