Delete images for existing product using rest api

$image_id = $existing_product_images[$k]->id;
$del_imag = ‘https://’ . API_TOKEN . ‘:’ . API_SECRET . ‘@’ . API_URL . ‘/admin/products/’.$product_id.’/images/’.$image_id.’.json’;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $del_imag);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(‘Accept: application/json’, ‘Content-Type: application/json’));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, “DELETE”);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($curl);

$err = curl_error($curl);
curl_close($curl);

if ($err) {
echo “cURL Error #:” . $err;
} else {
print_r($response);
}

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.