New Shopify Certification now available: Liquid Storefronts for Theme Developers

Reference Metaobject in a Metafield using Shopify API

angellam278
Tourist
3 0 1

Hi, 

 

I'm fairly new to Shopify and I am trying to create a python script that adds products onto the page. The products will have a custom metafield with metaobjects as values. Below is the code I have right now: 

 

 

product_payload = {
            'product': {
                'title': row['Title'],
                'body_html': row['Description'],
                'product_type': 'painting',
                'variants': [{
                    'price': row['Price'],
                }],
                'metafield': {
                    'key': 'Artist',
                    'value': "test-artist",
                    'value_type': 'string',
                    'namespace': 'custom'
                }
            }
        }

        # Make the API request to create the product
        response = requests.post(admin,
                                 headers=headers,
                                 json=product_payload)

 

It says the product is successfully created, but the custom metafield value remains blank.

Any guidance will be greatly appreciated. 

Reply 1 (1)
DiogoTeix
Shopify Partner
1 0 0

I suppose you have you found a solution to your problem in the last 5 months ! I'm trying to do the same with no success so far. I tried (in Python) directly using requests as well as using ShopifyAPI but so far without success... Could you share the solution you found, please ?
Thanks a lot !