Retrieve a list of metafields from the resource's endpoint API - how is it supposed to work?

sun11
Visitor
3 0 1

Hi,

I have to return all metafields that are created in one store. The API call above just returns me an empty list even though I've created metafields and checked "Expose this metafield to Storefront API requests". It also says that it retrieves a list of metafields from the resource's endpoint. In this URL I don't see where i should provide the resource. 

 

https://your-development-store.myshopify.com/admin/api/2022-07/metafields.json

Can someone please explain how is this supposed to work? And could this request be used to return metafields for one resource only (for example Customers or Products).

If not is it possible to extract metafield values using this API?

/admin/api/2022-07/customers.json

I see there is a "fields" parameter that is supposed to show only certain fields, but I'm not sure how to make use of it.

 

 

Replies 3 (3)

danloomer
Shopify Staff
11 5 4

Hi @sun11 !

 

You can get a list of Metafields under a specific resource by specifying the resource's ID in the URL.

 

For example:

// get list of products
https://your-development-store.myshopify.com/admin/api/2022-07/products.json

// get details of product with ID 2342
https://your-development-store.myshopify.com/admin/api/2022-07/products/2342.json

// get metafields of product with ID 2342
https://your-development-store.myshopify.com/admin/api/2022-07/products/2342/metafields.json

 

You can read more about this API here, there are examples at the bottom of the page for getting metafields for different resource types: https://shopify.dev/api/admin-rest/2022-07/resources/metafield#get-metafields

 

danloomer_0-1663324308007.png

 

To learn more visit the Shopify Help Center or the Community Blog.

sun11
Visitor
3 0 1

Hey @danloomer,

Thank you for the answer. I'm aware of this solution but I'm afraid that this will really slow the execution. You are saying there is no way to return list of all existing metafields and then filtering it by resource? What I mean by this is, I need metafields for all resources that can have metafields (in this case it's:  Article, Blog, Collection, Smart Collection, Customer, Draft Order, Location, Order, Page, Product, Product Image, Product Variant and Shop). And only after I get the whole list of metafields to be able to filter it by the specific resource.

QLicks
Shopify Partner
2 0 0

Hi @danloomer 

Maybe now it is possible to retrieve list of metafields for products?

I just need list of metafield definition for resource, for example

products {
metafield1 {definition...}
metafield2 {definition...}
}
maybe available in GraphQL API?

Is there any change I can retrieve it?