Disconnect a product image from all variants the image is assigned to

Highlighted
Shopify Partner
7 0 1

Hi all,

 

I'm trying to disassociate all product images in bulk using REST API by making a PUT request to products/{id}/images/{id}.json endpoint. I'm trying to pass both empty array or null value without success e.g.:

{
  "image": {
	"id":"13881463996452",
	"variant_ids": []
  }
}

and

{
  "image": {
	"id":"13881463996452",
	"variant_ids": null
  }
}

I'm able to update product variant and pass null value to the image_id attribute but I should make an individual request for every variant I'm trying to remove the image from and that's not what I'm looking for.

 

Does anybody know a way to do it in bulk?

 

Thanks in advance and Happy New Year!

0 Likes
Highlighted
Shopify Staff
Shopify Staff
51 10 5

Hi there, 

 

Unfortunately there isn't a way to dissociate product images in bulk (i.e. with a single endpoint). You are however, able to delete a product image with the following endpoint: https://shopify.dev/docs/admin-api/rest/reference/products/product-image#destroy-2020-01 . Accordingly with the product ID and  image ID, you should be able to delete the image from the product. 

 

Using the graphQL admin API you are able to provide an array of image IDs that you would like to delete from the product https://shopify.dev/docs/admin-api/graphql/reference/mutation/productdeleteimages which may be more suitable for your use case. 

 

Cheers

 

 

0 Likes
Highlighted
Shopify Partner
7 0 1

Hi, 

 

Unfortunately, I don't need to delete the image, I just need to unlink it from all variants. So, if I want to un-assign an image from 50 variants I would need either to make 50 requests to Shopify or delete and re-upload the image.

It would be quite useful if the request option from my question was available.

 

Anyway, thanks for you reply.

1 Like