Export Variant IDs?

Highlighted
New Member
3 0 0

I've imported a large number of products into Shopify from a previous store database, which worked great! We're going to be using a "buy" button from an outside site, though, and I'd like to be able to just export a list of the products with the Variant ID's, so I can import those into the existing database on our end. Any way to do this?

0 Likes
Highlighted
Shopify Expert
4175 29 400

Why don't you just export all your products, and then use your spreadsheet to do that? Am I missing something here? When you export your products from Shopify, you get all your variants, so there is really nothing too special left for you to do, short of cutting out the crap you don't want.

???

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Highlighted
New Member
3 0 0

Well, I'm just trying to save time here, really. :)

I know it's inefficient, but we're running a parallel database on our site, which generates the individual "Buy Now!" buttons. If I could import the Variant ID's into that database, I could then have the script we're running allocate them to the various buttons. As far as I can tell, though, the Variant ID doesn't import with the rest of the product info, and Variant ID's are the only way to remotely put an item into a user's cart. Make sense?

Thanks for the reply!

0 Likes
Highlighted
Shopify Expert
4175 29 400

I see.. right, the CSV export is using the handle to deal with products and variants. 

Simply simple... use your fave script language (Ruby, Python, Javascript, PHP)... and just code up a quick loop. Grab all your products and their variants, and dump the variant ID's. 

 

Should not take more than a couple of minutes and you're gold. 

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Highlighted
New Member
3 0 0

Makes sense...except I don't know how to connect to Shopify's DB to do this. My ignorance on a lot of this stuff is showing, I'm sure - still learning. Is there any part of Shopify's documentation that I should look for?

0 Likes
Highlighted
Shopify Expert
4175 29 400

Here you go...

http://api.shopify.com/

With that, a few lines of code, your in... takes just minutes... and a one-off script like you need really does not merit an App... just use the login credentials from your Shop Admin: Apps->Manage Apps and then click private application.

Additionally, if you're really pressed for time, you could just use the Shopify gem and the built in CLI.

That would also make short work of this... allows you to script right away.

Best....

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Highlighted
Shopify Staff
Shopify Staff
5704 1 318

Here's a .rb script that I run from the command line. It exports the variant IDs from a shop to a .csv file:

require 'rubygems'
require 'shopify_api'

APIKEY = 'YOUR_API_KEY'
PASSWORD = 'YOUR_PASSWORD'
SHOPNAME = 'shopname'

CYCLE = 10 * 60

# Telling your shop who's boss.
ShopifyAPI::Base.site = "http://#{APIKEY}:#{PASSWORD}@#{SHOPNAME}.myshopify.com/admin"

# How many.
product_count = ShopifyAPI::Product.count
nb_pages      = (product_count / 250.0).ceil

# Do we actually have any work to do?
puts "Yo man. You don't have any product in your shop. duh!" if product_count.zero?

file = File.new( 'variants_id.csv', 'w' )
file.puts "Product Title,Variant Title,Variant Id"

# Initializing.
start_time = Time.now

# While we still have products.
1.upto(nb_pages) do |page|
  unless page == 1
    stop_time = Time.now
    puts "Current batch processing started at #{start_time.strftime('%I:%M%p')}"
    puts "The time is now #{stop_time.strftime('%I:%M%p')}"
    processing_duration = stop_time - start_time
    puts "The processing lasted #{processing_duration.to_i} seconds."
    wait_time = CYCLE - processing_duration
    puts "We have to wait #{wait_time.to_i} seconds then we will resume."
    sleep wait_time
    start_time = Time.now
  end
  puts "Doing page #{page}/#{nb_pages}..."
  products = ShopifyAPI::Product.find( :all, :params => { :limit => 250, :page => page } )
  products.each do |product|
    puts product.title
    variants = product.variants
    variants.each do |variant|
      puts "-- #{variant.title}"
      file.puts "\"#{product.title.gsub('"','""')}\",\"#{variant.title.gsub('"','""')}\",#{variant.id}"
    end
  end
end

file.close

puts "Over and out."

The header is Product Title,Variant Title,Variant Id.

 

1 Like
Highlighted
New Member
4 0 0

This script is immensely useful, but with the newest version of the Shopify Ruby gem, it's no longer compatible. any chance of an update?

0 Likes
Highlighted

Checkout this command-line program. It works with the latest API and supports outputting to a CSV or to a customizable JSON format. 

ScreenStaring
Software Development & Consulting
0 Likes