Trying to get a list of Metafields for Products

I’ve trying to retrieve a list of metafields that belong to Products using the Admin API. When I query all at:

/metafields.json?

I get only the metafields with the owner_resource of “shop” - even if I specify:

/metafields.json?owner_resource=product

I still only get the shop metafields. I see this is something that’s been brought up here but I can’t find a solution. Thanks!

:waving_hand: Hi @RebeccaMG , I’d like a little more clarification on the exact URL you’re doing a GET on.

Looking at our REST API info here, the section titled “Retrieve a list of metafields by using query parameters” suggests you could use a URL similar to:
/admin/api/2022-10/metafields.json?metafield[owner_id]=<PRODUCT_ID>&metafield[owner_resource]=product

Alternatively, you might be able to get at what you want by following the examples in the section “Retrieve a list of metafields from the resource’s endpoint” at the same REST API info link above. An example URL for this is below. Note that there is no owner_resource param here as the resource type is indicated in the URL already.
/admin/api/2022-10/products/<PRODUCT_ID>/metafields.json

I wasn’t sure which endpoint you were attempting to use, so I provided both examples. Hopefully one of these two methods can get you what you need. Please let me know if one of these helps any? I’m happy to dig in further with you if not.

1 Like

Thank you! This was the help I needed.