Skip to content

Instantly share code, notes, and snippets.

@vutran0111
Last active October 3, 2017 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vutran0111/a58ebb580db9b4394fa89ad5025dc07a to your computer and use it in GitHub Desktop.
Save vutran0111/a58ebb580db9b4394fa89ad5025dc07a to your computer and use it in GitHub Desktop.

Example for a private App (gimmie_app)

1. Create base site url

API_KEY   = '9fb1d3774a34b2704a464d9cc2bd86db'
PASSWORD = 'a931fdeff8d1de0426695286910fecec'
SHOPNAME = 'gimmietest'
url = "https://#{API_KEY}:#{PASSWORD}@#{SHOPNAME}.myshopify.com/admin"
ShopifyAPI::Base.site = url

2. Create new product, order

  • Create new product
    new_product = ShopifyAPI::Product.new
    new_product.title = "Burton Custom Freestlye 151"
    new_product.product_type = "Snowboard"
    new_product.vendor = "Burton"
    new_product.save
    
  • Create new Order pending
    order = {
      "line_items": [
        {
          "title": "Red Leather Coat",
          "price": 129.99,
          "grams": "1700",
          "quantity": 1
        },
        {
          "title": "Blue Suede Shoes",
          "price": 85.95,
          "grams": "750",
          "quantity": 1,
          "taxable": false
        },
        {
          "title": "Raspberry Beret",
          "price": 19.99,
          "grams": "320",
          "quantity": 2
        }
      ],
      "tax_lines": [
        {
          "price": 10.2,
          "rate": 0.06,
          "title": "State tax"
        },
        {
          "price": 4.25,
          "rate": 0.025,
          "title": "County tax"
        }
      ],
      "total_tax": 14.45,
      "financial_status": "pending"
    }
    ShopifyAPI::Order.create(order)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment