Reputation: 41
Is there a way to GET the metafields for a particular product if I have the product ID? Couldn't find it in the docs.
Upvotes: 4
Views: 2838
Reputation: 3283
You can do it the way @lihuangxiao suggests in his answer. But modify it slightly to avoid two API calls:
product = shopify.Product({id: product_id})
metafields = product.metafields()
Upvotes: 0
Reputation: 105
A easy way to do it in python would be:
product = shopify.Product({"id" : product_id})
metafields = product.metafields()
Note that the above would be one API call, finding product and then metafields would be two API calls:
product = shopify.Product.find(product_id)
metafields = product.metafields()
a bit hacky but works well with the python package
Upvotes: 1
Reputation: 309
product = shopify.Product.find(pr_id)
metafields = product.metafields()
Upvotes: 0
Reputation: 4239
The call you want is shopify.Metafield.find()
>>> shopify.Metafield.find()
[metafield(1), metafield(2), metafield(3)]
You can also pass in filters
>>> shopify.Metafield.find(namespace='myapp')
[metafield(1), metafield(2)]
The Python API has almost zero documentation which makes figuring these things out an exercise in frustration.
Upvotes: 4
Reputation: 695
You should be able to use the Metafields API. In particular, you can use the endpoint
GET /admin/products/#{id}/metafields.json
to get metafields that belong to a particular product.
Upvotes: 0