SmartCollection API bug - deletes image when updating

Shopify Expert
403 29 77

This is a strange one... I can't update a collection description without the collection featured image being deleted.

 

Here's what happens (using the shopify_app gem with Rails):

 

I update a collection description, then save it:

 

# Get the collection
collection = ShopifyAPI::SmartCollection.find(:all, params: { handle: current_user.handle })
collection = collection[0]

# Update the description
collection.body_html = "New description"

# Save
collection.save

 

 

 

I get an error (from collection.errors) that says:

{"base":["Image upload failed. Image https://cdn.shopify.com/...image_url.png failed to download. - file not found. Check that file can be found at your URL."]}

 

I've tested various scenarios and have it narrowed down to this. Even without updating the collection description, just doing collection.save action deletes the image.

 

When I read the collection, the image is fine and shows up (this is in a private app). So it exists right until the point I make the API call with collection.save.

 

When refreshing the collection in Shopify after running the update, the image is now deleted.

 

I can upload a new image fine, it saves. But when updating the image it deletes it.

 

Any idea what's wrong here?

 

 

Founder of Speed Boostr (Shopify optimization and dev agency).
Creator of Order Automator (app that auto fulfills orders, adds tags, emails).
Creator of Shopify Analyzer (free performance analysis tool).
I also build custom apps and automated solutions.
Enjoy the adventure!
0 Likes
Highlighted
Shopify Expert
9811 92 1561

What happens when you make the same call via Postman or something similar? It's a good step to always test as it helps rule or prove your stack/library being the issue.

 

What's the actual data that you're sending? If you don't capture that it would also be worthwhile doing that. Possible more info is being sent than what you think.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Shopify Expert
403 29 77

Thanks Jason those are good general practices I agree. The collection object in this case sends the same data on both fail and success, so it hasn't helped me much for debugging.

 

It's the same stack I typically use for Shopify apps / scripts, but haven't used the SmartCollection API before so part of me is thinking it's a bug... unlikely probably but since it only happens sometimes, I haven't been able to target an exact cause.

 

I have a few other tests I'm trying to isolate it, just wondering if anyone else had an issue like this.

Founder of Speed Boostr (Shopify optimization and dev agency).
Creator of Order Automator (app that auto fulfills orders, adds tags, emails).
Creator of Shopify Analyzer (free performance analysis tool).
I also build custom apps and automated solutions.
Enjoy the adventure!
0 Likes
Shopify Expert
403 29 77

2 interesting point to add after testing today:

 

1) Random inconsistency

I set the collection.image as a static external image, then tried updating the collection programmatically  10 times.

 

2 out of 10 times the request failed and the collection image was deleted.

 

Examples from my logs:

 

=> BEFORE SAVE (after manually setting collection.image with a static src)
{"src"=>"http://placehold.it/500x500"}


=> AFTER SAVE (Shopify uploaded the image into its cdn after I called collection.save)
{"created_at":"2019-12-13T20:05:30-05:00","alt":null,"width":500,"height":500,"src":"https://cdn.shopify.com/s/files/1/0013/4869/8160/collections/500x500.png?v=1576285532"}

(This is what should happen)

 

... another attempt:

==> BEFORE SAVE
{"src"=>"http://placehold.it/500x500"}

 

==> AFTER SAVE
{"created_at":"2019-12-13T20:08:35-05:00","alt":null,"width":500,"height":500,"src":"https://cdn.shopify.com/s/files/1/0013/4869/8160/collections/500x500_c63592ff-5e36-4a20-b807-178616e..."}

(Weird that now it decided to add a guid. Maybe that's because the old file still existed but I'd think it would just overwrite)

 

... and a failed attempt:
==> BEFORE SAVE
{"src"=>"http://placehold.it/500x500"}


==> ERROR
{"created_at":"2019-12-13T20:09:40-05:00","alt":null,"width":500,"height":500,"src":"https://cdn.shopify.com/s/files/1/0013/4869/8160/collections/500x500.png?v=1576285780"}

(looks like it uploaded fine...)

 

{"base":["Image upload failed. Image https://cdn.shopify.com/s/files/1/0013/4869/8160/collections/500x500.png?v=1576285780 failed to download. - file not found. Check that file can be found at your URL."]}

(...but then couldn't access the file)

 

So then what happens is the collection image is deleted.

 

 

2) Image is deleted even without touching the image property

I did a basic test:
1) manually upload an image in the collection in Shopify

2) get collection (collection = ShopifyAPI::SmartCollection.find(collection_id))

3) update description (collection.body_html = "yooooo")

4) save collection (collection.save)

 

This even fails (sometimes). Even though I don't edit the image at all, eventually it will give me that "image upload failed" error and then delete the image.

 

I'm stumped 🤔

 

Using:

- Shopify REST API 2019-10

- SmartCollection endpoint

- shopify_api gem v8.0.0

 

 

Founder of Speed Boostr (Shopify optimization and dev agency).
Creator of Order Automator (app that auto fulfills orders, adds tags, emails).
Creator of Shopify Analyzer (free performance analysis tool).
I also build custom apps and automated solutions.
Enjoy the adventure!
0 Likes
Shopify Expert
403 29 77

Anyone finding this in the future: don't waste your time trying to make it work.

 

It's a known bug with the shopify_api gem: https://github.com/Shopify/shopify_api/issues/630

 

As a workaround, you can do a regular HTTP request and it updates properly.

Founder of Speed Boostr (Shopify optimization and dev agency).
Creator of Order Automator (app that auto fulfills orders, adds tags, emails).
Creator of Shopify Analyzer (free performance analysis tool).
I also build custom apps and automated solutions.
Enjoy the adventure!
0 Likes