I am looking to automatically publish items to a shopify store from an existing web-app. I need to be able to create items with images to do so. I have been able to create items on shopify via the python api - but am not sure on how to add the images. Here is what I have right now:
all_products = Product.objects.all()[0:7]
for p in all_products:
    images=[]
    image={}
    image["src"] = p.image.url
    new_product = shopify.Product()
    new_product.product_type = p.category()
    new_product.body_html = p.description
    new_product.title = p.caption
    new_product.vendor = "atisundar"
    new_product.images = images
    new_product.save()
How do I add images to this?
new_product.images does not seem to work.
Any and all help is greatly appreciated. :-)
Thank you.
I figured it out. :-)
    new_product = shopify.Product()
    new_product.product_type = p.category()
    new_product.body_html = p.description
    new_product.title = "atisundar "+ p.caption
    new_product.vendor = "atisundar"
    image1 = shopify.Image()
    image1.src = p.image.url()
    new_product.images = [image1]
    new_product.save()
                        I know the question has already been answered but there is an alternate method here as well.
new_image = shopify.Image(dict(product_id=product.id))
new_image.src = "http://someurlhere"
new_image.save()
If you already have the product ID saved in a database, for example, then you can use this route and save yourself a call to the API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With