add product variant shopify python api

Solutions on MaxInterview for add product variant shopify python api by the best coders in the world

showing results for - "add product variant shopify python api"
Georgie
05 Mar 2016
1new_product = shopify.Product()
2new_product.title = "My Product"
3new_product.handle = "test-product"
4
5##what I've tried... and countless others
6#First example of new_product.variants
7new_product.variants = shopify.Variant({'options': {'option1' : ['S', 'M', 'L', 'XL'], 'option2' : ['Black', 'Blue', 'Green', 'Red']}, 'product_id': '123456789'})
8#Second example of new_product.variants
9new_product.variants = shopify.Variant({'options': [{'option1': 'Size', 'option2': 'Colour','option3': 'Material'}]})
10#Thrid example of new_product.variants
11new_product.variants = shopify.Variant([
12                      {'title':'v1', 'option1': 'Red', 'option2': 'M'},
13                      {'title':'v2', 'option1' :'Blue', 'option2' :'L'}
14                      ])
15new_product.save()
16##No errors are output, but doesn't create variants with options
17if new_product.errors:
18    print new_product.errors.full_messages()
19print "Done"