# removeProductMedia

**URL:** <https://forum.wixstudio.com/t/removeproductmedia/6370>\
**Category:** Ask the community\
**Tags:** code, question, wix-stores\
**Created:** [October 11, 2021, 5:12pm UTC](https://forum.wixstudio.com/t/removeproductmedia/6370 "2021-10-11T17:12:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![myapps20000](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@myapps20000](https://forum.wixstudio.com/u/myapps20000)\
**Post date:** [October 11, 2021, 5:12pm UTC](https://forum.wixstudio.com/t/removeproductmedia/6370/1 "2021-10-11T17:12:33Z")

</div>

```javascript

/ *******************************
 * Backend code - products.jsw *
 ******************************* /

import wixStoresBackend from 'wix-stores-backend';

export function removeProductMedia(productId, media) {
  return wixStoresBackend.removeProductMedia(productId, media);
}

/ *************
 * Page code *
 ************* /
import wixData from 'wix-data';
import { removeProductMedia } from 'backend/products';

// ... 

const productName = ...; // get name of product 

wixData.query("Stores/Products")
  .eq("name", productName)
  .find()
  .then((results) => {
    if (results.items.length > 0) {
      const productId = results.items[0]._id;
      removeProductMedia(productId) // not passing media will remove all media from product
        .then(() => {
          // all media items removed from the product 
        })
        .catch((error) => {
          // media items not removed from the product 
        });
    }
  });

```

I refer to the above example code from the velo document. In the example the media item is not specified. I was trying to write a code with specified media (i.e. with src url) but I cant figure in what format the media para. should be in… all my attempts failed and the command was just ignored. Anyone can give me an example code for that?

---

<div class="post-metadata">

**Author:** ![myapps20000](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@myapps20000](https://forum.wixstudio.com/u/myapps20000)\
**Post date:** [October 11, 2021, 5:17pm UTC](https://forum.wixstudio.com/t/removeproductmedia/6370/2 "2021-10-11T17:17:52Z")

</div>

I have tried

```javascript
var productId = 
var src = 'www.////'
var mediaData = {src} 
removeProductMedia(productId,mediaData)

```

not working. And none of the below works either.

```javascript
var mediaData = src
var mediaData = [{src}]
var mediaData = [src]
var mediaData = [{
src
} ]
var mediaData = [{src},,] 

```

---

<div class="post-metadata">

**Author:** ![chris-derrell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/chris-derrell/32/1774_2.png) [@chris-derrell](https://forum.wixstudio.com/u/chris-derrell)\
**Post date:** [October 12, 2021, 12:36pm UTC](https://forum.wixstudio.com/t/removeproductmedia/6370/3 "2021-10-12T12:36:09Z")

</div>

Hey @myapps20000 , it looks like you may have just copied the snippet there into only your page code OR backend code. You’ll notice that there are two parts to it, with the comments highlighting each section. Those pieces of code are to go into two separate files (backend/products.jsw and your page code).

The issue you’re probably having is with the imports themselves.

```javascript
import wixStoresBackend from 'wix-stores-backend'; //This needs to be in a backend file.

```

:point_up_2: can’t work in the page code on the front end, because the modules it requires to work are specific to Wix’s backend environment, running on node.js.

If this doesn’t solve it, what you can do is in the line where you have .catch((error)=\>{, add a console.error so you can see the full error message and how to fix it in your console. That would look be like this.

```javascript
.catch((error)=>{
    console.error(error);
});

```

---

<div class="post-metadata">

**Author:** ![myapps20000](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@myapps20000](https://forum.wixstudio.com/u/myapps20000)\
**Post date:** [October 12, 2021, 4:57pm UTC](https://forum.wixstudio.com/t/removeproductmedia/6370/4 "2021-10-12T16:57:49Z")

</div>

I have already done that. The example code works just fine with no media specific, which deletes all images of the product. But in the document it says there is a way to specify which media to delete, which I don’t know what to put in the {media} para.

---

<div class="post-metadata">

**Author:** ![myapps20000](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@myapps20000](https://forum.wixstudio.com/u/myapps20000)\
**Post date:** [October 21, 2021, 10:32am UTC](https://forum.wixstudio.com/t/removeproductmedia/6370/5 "2021-10-21T10:32:20Z")

</div>

up
