I am trying to add a new product through the Python Shopify API. I know how to add title and body and a picture but I am having issues with adding price and I need to have 'requires_shipping': False. I can't find anywhere how to achieve this.
This is what I have so far.
import shopify
API_KEY = 'dsfsdsdsdsdsad'
PASSWORD = 'sadsdasdasdas'
shop_url = "https://%s:%[email protected]/admin" % (API_KEY, PASSWORD)
shopify.ShopifyResource.set_site(shop_url)
path = "audi.jpg"
new_product = shopify.Product()
new_product.title = "Audi pictures test "
new_product.body_html = "body of the page <br/><br/> test <br/> test"
###########this part is so far good. but the bottom part is not working####
variant = shopify.Variant(price=9.99)) # this does not work
new_product.variant() # this does not work
variant_2 = shopify.Variant(requires_shipping=False) #this does not work
new_product.variant_2() This does not work
image = shopify.Image()
with open(path, "rb") as f:
filename = path.split("/")[-1:][0]
encoded = f.read()
image.attach_image(encoded, filename=filename)
new_product.images = [image] # Here's the change
new_product.save()
Only prefix options (e.g.
product_idfor Variants,order_idfor Fulfillments) should be passed as explicit parameters to the constructor. If you want to initialize the attributes of the resource you'll need to pass them in as a dict.You're also not associating your new variant with your new product at any point.
This should help:
You can also specify the attributes of the resource after initializing, as you're already doing for the Product resource.
Another option would be to save the product first and initialize the variant by passing the
product_idexplicitly, e.g.shopify.Variant(product_id=1234567)Take a look at the README for more usage examples.