user2996806
user2996806

Reputation: 41

Shopify Python API GET Metafields for a Product

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

Answers (5)

mridula
mridula

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

lihuangxiao
lihuangxiao

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

Sergey
Sergey

Reputation: 309

product = shopify.Product.find(pr_id)

metafields = product.metafields()

Upvotes: 0

Rebs
Rebs

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

Richard Ye
Richard Ye

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

Related Questions