Shopify – python api (shopify.SmartCollection.create)

Yep.. I’ve joined the dark side.. from .net to python.. What is more I’m moving away from Ecommerce Sites that i have built from scratch to the more universal Shopify Platform (at least for evaluation reasons)

On first blush this may be better as an ecommerce site than i expected. It has some shocking limitations like only supporting a VERY limited number of payment gateways and having little to no concept of an ACH transaction (ones that take money directly from a persons bank account.. WAY cheeper than running credit card transactions..

One of my tasks was to see if we could write code to generate a menu based on our products taxonomy. Out of the box our company sells around 130 different categorys and if we didn’t script this creation it would be really easy to have unreachable products after the import. The fact that Shopify doesn’t really even understand categories isn’t that much of a problem.. What it does have is “collections”, “collections” come in 2 flavors, dynamic and static.

Because we want automatic incorporation of products as they are uploaded into Shopify the correct choice is dynamic.

So.. how did we manage to script the creation.. Most of the documentation is in PHP.. but our current flavor of language is python and as much as it is probably possible to just convert the code over, shopify was nice enough to create a PYTHON based api that allows you to work with both the ADMIN api and STOREFRONT api. The ADMIN api actually providing all the ability required to work with products or collections

You also need to generate API keys for shopify. To do this login to your store and create a new “app key”

  1. Log into your store and in theme actions click “Edit Code”
  2. On the next screen select “Apps” in the left hand menu.
  3. On the Apps Screen select (at the bottom of the page) “Manage Private Apps”
  4. If you don’t already have one click the button labeled “Create a new private app” (top right)
  5. On the next screen review all the permissions available and what they pertain to (select the ones you need)
  6. You will need the followitn values after going to your app (copy them somewhere)
    API key
    Shared secret
    and example u8rl (as a sanity check)
From the python side you need to install the Shopify Python API (docs:
  1. open a bash prompt
  2. use pip to install the api  pip install –upgrade ShopifyAPI
In this example I’m just going to create a simple python file that can be executed from a command prompt of some type. (bash or dos)
The first snippet is what is needed to use the API
import shopify


shop_url = "" % (API_KEY, PASSWORD, SHOP_NAME)


This adds a new collection called “rob test” that finds any products where the Product Type is “Stools” and adds them to the collection.

After adding the collection it prints the return from the create hopefully showing more detail about the new collection.

added = shopify.SmartCollection.create({
    "title": "rob test",
    "rules": [
        "column": "type",
        "relation": "equals",
        "condition": "Stools"
    "published": 'true'#
print ('---- added equals ------')
print (added.__dict__)
print ('---- end added  ------')

Listing all collections and their properties

x = shopify.SmartCollection().find()print('-------------------------------------------------------------')
# print x
for y in x:
# if y.attributes["title"] == "rob test":
# print y.__dict__# prints all the properties of the collection
# print y.attributes['title']
print y.__dict__
# the properties are all stored in a dictionary.. you can loop through
# them if needed. print('-------------------------------------------------------------')

Jquery Plugin to only allow numeric input..

Ok.. so this is my first Jquery Plugin – VERY SIMPLE…

All it does is attach to the keydown of any element it is attached to and look to see if the key being pressed is numeric via a regular expression. Nothing fancy. no periods, no commas, no currency formatting.

Useful for making sure credit card numbers or bank account numbers are being entered correctly in a web page.

(function($) {
    $.fn.PreventNonNumeric = function() {
            function(x) {
                if (x.key.replace(/\D/, "") == ""|| x.key === "Spacebar")
                { x.preventDefault(); }

        return this;
})(jQuery, event);

Attach to an element as




Rebuilding the UMBRACO Undex’s

There is an off chance that your index files in UMBRACO ( umbraco.config ) may become corrupt. If this is the case there is a nice built-in utilitie that can be used to rebuild all the index’s and fix the issues that your site is experiencing.

add the following to your website’s root address “Umbraco/dialogs/republish.aspx?xml=true”

e.g. if the site was you would enter

Follow the prompts.

I found myself having to use this to fix a problem where the Dynamic menus were adding nodes that didn’t exist and breaking links on nodes that did.

Quick and easy fix

Well done umbraco team.


CMS Systems.. (UMBRACO)

I have reciently started looking at what i feel to be a superior CMS system that is both intuative and powerfull. It’s name is UMBRACO and is based on the .net framework. To make learning the system easy, they have a great series of video tutorials that will allow a dotnet developer to quickly take advantage of this platform and end users to do much the same.

From the developers perspective after you have loaded the site on your system I would recomend the following videos (free) – it is also worth mentioning that a lot of the videos have tutorial documents that are linked to them at the bottom right hand corner.. These are defniitely worth grabbing as they contain sample code used in the tutorial and can help to jump start understanding.

So.. in order of what makes sense of you are thinking about creating a “Custom” umbraco installation.

(start here - select free to eliminate videos that you cant view – but it is worth getting the full series.. I would just review all the free content before you purchase your subscription..)


PS.. as i work through the tutorials and gain a greater undrstanding this page will get updated (probably quite quickly)


Java Script Libs worth looking at.

Of course you need to start with

JQuery, JQueryUI, JQuery Mobile but there are a number of other libs that are worth keeping an eye on.







Kill “right click” from a webpage with JQuery

This was always a pain with pure javascript, however Jquery has made our lives infinatly easier. Just bind to the “contextmenu” object and kill any action.

return false;