Skip to content

Instantly share code, notes, and snippets.

Last active August 23, 2016 11:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Upload product images using the Bootic Ruby client library
# Full tutorial:
require 'bootic_client'
# Configure the client with your credentials
BooticClient.configure do |c|
c.client_id = 'MY_CLIENT_ID'
c.client_secret = 'MY_CLIENT_SECRET'
c.logger = # optional
c.logging = true # optional
c.cache_store = Rails.cache # optional
# Instantiate a client
client = BooticClient.client(:client_credentials, scope: 'admin')
# Fetch the root resource and your default shop
root = client.root
shop = root.shops.first
# all products in your shop
products = shop.products(status: 'all').full_set
# Iterate products and upload matching images.
products.each do |product|
# ex. "apple-iphone-6-plus.jpg"
file_name = "#{product.slug}.jpg"
file_path = File.expand_path(File.join(".", "images", file_name))
if File.exists?(file_path) && product.has?(:create_product_asset)
# An instance of File
image_file =
# Pass the file to #create_product_asset
image = product.create_product_asset(
file_name: file_name,
data: image_file,
title: product.title
if image.has?(:errors)
puts "Error uploading image for #{product.slug}: #{image.errors.first.messages.first}"
puts "Uploaded image for #{product.slug}"
puts "No images for product #{product.slug}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment