Shopify API Update Products Based on Conditions

If you already have a private app setup in a rails environment, skip the first step and go into your rails console.

If you don’t have a rails environment but you’re running on a mac or linux environment, you may already have ruby installed and all you have to do is install the shopify_api gem and enter into the shopify console environment with the following:

gem install shopify_api

shopify add [SHOPIFY_SHOP]

Once you fill in the answers to the questions for credentials you can run

shopify console

Now that we’re in the same environment, we can instantiate our session and add our ShopifyAPI module and find and update our products

//Add shopify module
include ShopifyAPI

//Instantiate our site
Base.site = "https://[SHOPIFY_SHOP_API]:[SHOPIFY_PASSWORD]@[SHOPIFY_SHOP].myshopify.com/admin"

//Select all products in store
products = Product.all

//Select only products with a price of zero
zerop = products.select {|p| p.variants.any? {|z| z.price == '0.00'}}

That’s it! Now you can use the variable to update any product field you desire.

Start your shop on shopify today! (My referral link)