shopify-api-ruby: Deleting a Product Image resource fails API v 3.4.2

Given a Product with Images we can iterate product.images

Given an instance of an image eg:

img = ShopifyAPI::Product.find(260391085).images.first
=> #<ShopifyAPI::Image:0x007fb4b9375bc0 @attributes={"created_at"=>"2014-03-08T20:37:26-05:00", "id"=>570863025, "position"=>1, "updated_at"=>"2014-03-08T20:37:26-05:00", "src"=>"https://cdn.shopify.com/s/files/1/0084/3892/products/calice1_2013.jpg?v=1394329046"}, @prefix_options={:product_id=>260391085}, @persisted=true>

We can see we get the parent product ID in the product_options attribute:

@prefix_options={:product_id=>260391085}

Trying to delete this image resource fails however.

ShopifyAPI::Image.delete(img.id)
ActiveResource::MissingPrefixParam: product_id prefix_option is missing

It would be nice to factor image resource deletes into the API.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@resistorsoftware If you want a cleaner syntax option, try:

image = ShopifyAPI::Product.find(260391085).images.first
image.destroy

@resistorsoftware The following should work for deleting the image – if not please let me know :

image = ShopifyAPI::Product.find(260391085).images.first
ShopifyAPI::Image.delete(image.id, product_id: 260391085)

cc: @pickle27 You were close! 😃

I think you just need to provide a product id and it will work the way you want. For example this is how we fetch an image directly using the api:

image = ShopifyAPI::Image.find(850703190, :params => {:product_id => 632910392})