3
votes

I am using the shopify Python API. There is only a short tutorial at

http://wiki.shopify.com/Using_the_shopify_python_api

and it doesn't include anything about metafields. I am not sure how I am meant to translate the shopify API into commands for the Python API. Specifically I would like to know how to add metafields to Shopify resources, for example to a Custom Collection.

Thanks!

2

2 Answers

5
votes

Metafields have two prefix options, resource and resource_id, otherwise they are like other resource.

So the create Metafield create action in the API documentation can be performed as follows.

metafield = Metafield({'value_type': 'integer', 'namespace': 'inventory', 'value': 25, 'key': 'warehouse', 'resource': 'products', 'resource_id': 632910392})
metafield.save()

There is also an add_metafield method on resources that can take metafields to simplify the above to the following.

product = Product.find(632910392)
metafield = Metafield({'value_type': 'integer', 'namespace': 'inventory', 'value': 25, 'key': 'warehouse'})
product.add_metafield(metafield)
-1
votes

There is API documentation here in regards to using metafields in the Shopify API.