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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

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