Jump to content

How To Delete Product Images Via Web Service

Recommended Posts




I can successfully delete the whole product using this code:

$webService->delete(array('resource' => 'products', 'id' => '11192'));

But I just want to delete the product images and keep the rest of information. I've tryed this way but it doesn't work:

$webService->delete(array('resource' => 'images/products', 'id' => '11192'));

It runs without errors/warnings but don't delete the picture.



Can anyone help me?

Tanks in advance.

Share this post

Link to post
Share on other sites

I once found an example of Prestashop web-service Library of deleting objects(images) via web service 

// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://www.myshop.com/');
if (isset($_GET['DeleteID']))
    echo '<h1>Customers Deletion</h1><br>';
    // We set a link to go back to list
    echo '<a href="?">Return to the list</a>';
        $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
        // Call for a deletion, we specify the resource name and the id of the resource in order to delete the item
        $webService->delete(array('resource' => 'customers', 'id' => intval($_GET['DeleteID'])));
        // If there's an error we throw an exception
        echo 'Successfully deleted !<meta http-equiv="refresh" content="5"/>';
    catch (PrestaShopWebserviceException $e)
        // Here we are dealing with errors
        $trace = $e->getTrace();
        if ($trace[0]['args'][0] == 404) echo 'Bad ID';
        else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
        else echo 'Other error<br />'.$e->getMessage();
    // Else get customers list


Hopefully it'll assist you with excursion.

Regard Jacob

Share this post

Link to post
Share on other sites
Posted (edited)

The correct answer is this

Operation: HTTP DELETE
URL : www.shop.com/api/images/products/<product-id>/<image-id>

If you are using the webservice API then 
resource = "images/products/<product-id>"
id = <image-id>

$webService->delete(array('resource' => 'images/products/<product-id>', 'id' => '<image-id>'));


Edited by tobiaseriksson (see edit history)

Share this post

Link to post
Share on other sites

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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More