Jump to content

Someone was able to modify existing images of a product using the api?


qhe

Recommended Posts

I have two weeks testing and looking for documentation but I can not do it.

I have prestashop 1.5.4.1 and use this code from Chapter 9 - Image management. It works to add images but not modify:

I want to change the image 33 of the product 9 with a new image

 

<?php
define('PS_SHOP_PATH', 'http://myhost.com/testshop/api/images/products/9/33'); // id_product = 9 id_image = 33 (33.jpg)
define('PS_WS_AUTH_KEY', 'RNOLmy key');
$img=$_SERVER["DOCUMENT_ROOT"].'/testshop/img/tmp/newimagefor33.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, PS_SHOP_PATH);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image . I do it
curl_setopt($ch, CURLOPT_USERPWD,  PS_WS_AUTH_KEY.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$img));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
?>

 

It does not work (does nothing)

<?php
define('PS_SHOP_PATH', 'http://myhost.com/testshop/api/images/products/9/33'); // id_product = 9 id_image = 33 (33.jpg)
define('PS_WS_AUTH_KEY', 'RNOLmy key');
$img=$_SERVER["DOCUMENT_ROOT"].'/testshop/img/tmp/newimagefor33.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, PS_SHOP_PATH);
//curl_setopt($ch, CURLOPT_POST, true); //<--- I comment this
curl_setopt($ch, CURLOPT_PUT, true); // Un-commet to edit an image
curl_setopt($ch, CURLOPT_USERPWD,  PS_WS_AUTH_KEY.':');
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$img));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
?>

 

It does not work.

 

What am I doing wrong?

Is there another way?

Could delete the image and then add it back. Anyone know how to delete an existing image using the api?

 

 

Thank you very much.

Regards,

 

Quim

Edited by qhe (see edit history)
Link to comment
Share on other sites

  • 2 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...