What is the best way to delete all products programmatically?

Shopify Partner
61 0 13

I'm wondering what the best/fastest way is to delete all products programmatically (preferably using Ruby).

What are you experiences?

Cheers!

0 Likes
Shopify Staff
Shopify Staff
591 0 45

You don't need to use Ruby to do that. You can simply go into your admin, click on Select all 50+ Products and choose the Delete Products from the bulk actions menu.

 

Note that this says orders, that is simply because I don't have more than 50 products in my Shop.

0 Likes
Shopify Partner
61 0 13

I want to be able to do this programmatically every night at 04:00 before adding new products. Any ideas?

0 Likes
Shopify Staff
Shopify Staff
591 0 45

The best way to do it reliably would be to use that feature (which doesn't have an API action yet).

You could probably pull it off using a screen scraper, but I believe you'll need to use phantomJS or something because there is some JS that needs to run.

0 Likes
Excursionist
70 0 14

Hey Narek, to answer your question about doing it programmatically in ruby, and for whomever else is curious, here's one way to bulk-delete products:

ShopifyAPI::Product.where(limit: 250).map(&:destroy) while ShopifyAPI::Product.count > 0

Hope this helps!

Product Customizer - Creating extremely customizable products within Shopify is no longer a hassle! BlogFeeder - Automatically pull updates from any RSS feed into your Shopify blog Happy Ending - Personalize your thank you page
0 Likes
Shopify Partner
61 0 13

You're awesome Justin!

Thanks a lot :).

0 Likes
Highlighted
Shopify Staff
Shopify Staff
591 0 45

Keep in mind while your Ruby code is minimal, all those destroy calls consume your API limit, so 429s are still most likely going to happen.

0 Likes
Excursionist
70 0 14

Good point, I should have said this is with the assumption that 429's are being handled in the background.  We've had success using Scott Wheeler's monkey-patch of ActiveResource::Connection as described here: https://ecommerce.shopify.com/c/api-announcements/t/upcoming-change-in-api-limit-calculations-159710...

Product Customizer - Creating extremely customizable products within Shopify is no longer a hassle! BlogFeeder - Automatically pull updates from any RSS feed into your Shopify blog Happy Ending - Personalize your thank you page
0 Likes