Hi,
I’m trying to add a product to Shopify using the ShopifyAPI Python package.
I’m using the following code:
shop_url = "https://%s:%s@1946de-3.myshopify.com/admin" % (config('SHOPIFY_KEY'), config('SHOPIFY_SECRET'))
shopify.ShopifyResource.set_site(shop_url)
new_product = shopify.Product()
new_product.title = product.title
new_product.body_html = product.description
new_product.vendor = str(product.stockrecords.first().partnernew_product.product_type = product.categories.first().name
new_product.images = [{'src': STATIC_BASE_URL + str(item.original)} for item in images]new_product.status = 'active'
new_product.metafields = [
{
'key': 'extra_informatie',
'value': '{"type":"root","children":[{"type":"paragraph","children":[{"type":"text","value":"Dit is extra info!"}]}]}',
'type': 'rich_text_field',
'namespace': 'custom'
}
]
success = new_product.save()
variant = new_product.variants[0]
variant.price = price
variant.taxable = True
variant.sku = product.stockrecords.first().partner_sku
variant.inventory_management = 'shopify'
variant.inventory_policy = 'continue'
success_variant = variant.save()
Everything is showing up fine in the Shopify admin, but the metafields remain empty.
What am I doing wrong?