Reputation: 237
I have been trying to get metafields for over 100 products and that means I have to make separate 100 api calls for each product. If there is a way to grab all metafields for all products just in one xml file like the way variants are attached to products. So that with one api call, i grab all 100 products instead of making 100 separate api call for each product. Any help is appreciated.
Upvotes: 20
Views: 4546
Reputation: 5330
It would be nice if it was mentioned in the API doc though. Nothing about
Receive a list of all Metafields GET /admin/metafields.json?since_id=721389482
indicates it will only return shop metafields.
Upvotes: 2
Reputation: 1522
We have had a lot of requests for getting metafields for multiple resources in the same request. However, a lot of them could be handled by keeping the information at the applications side (e.g. in a database), along with the id of the resource. This way the data is closer to where it is being used.
There are two very good reasons for using metafields
Metafields for liquid templates is great because the data is close to where it will be used for page rendering. This makes rendering fast and more customizable, because custom fields can be provided by apps and rendered in the storefront.
Shared storage between applications is another good reason to use metafields, but it doesn't appear to be a common reason metafields are used. In this case the metafields API is currently lacking a way to access metafields on multiple resources at once.
Returning metadata along with products, however, is not a very good option. This is because other applications may store data in metafields that your application might not care about, so one application could end up slowing down a lot of other applications that don't even use metafields. This is why the metafields API has query parameters to restrict what metafields being retrieved, so metafields for other applications aren't returned unnecessarily.
Upvotes: 1