Shopify API


Few weeks ago, one of my friends asked me about adding new features to his Shopify.com based online shop.

So, I started from their API of course - it’s well documented and very clear Documentation.

First of all I created my own shop for test purposes, and added some test products.

Test Products

In next step, you should go to the private apps admin panel section and generate your credentials.

PWD

Install gem:

gem install 'shopify_api'

Super simple API:

require 'shopify_api'

SHOPIFY_SHOP='kazansoccer.myshopify.com'
SHOPIFY_API_KEY='XXX'
SHOPIFY_PASSWORD='XXX'

ShopifyAPI::Base.site = "https://#{SHOPIFY_API_KEY}:#{SHOPIFY_PASSWORD}@#{SHOPIFY_SHOP}/admin"

# get orders
orders = ShopifyAPI::Order.find(:all, params: { created_at_min: (Time.now - 30.days), limit: 250 })

# get shop instance
shop = ShopifyAPI::Shop.current

# get products
products = ShopifyAPI::Product.find(:all, params: { limit: 250 })

# just print product titles
puts products.map { |x| x.title }

Result:

marat at Marats-MacBook-Pro-2 in ~/Sandbox 
$ ruby shop.rb
["AS Roma T-Shirt", "Totti T-Shirt"]

Stay tuned, I’ll write some new posts about shop customization.