Get all metafields for products

Excursionist
28 1 4

Thanks HunkyBill. 

Maybe you could help me figure out the logic for this.

I'm creating a private app for my client. I was hoping to use metafields to allow us to change a binary option (true/false) for each customer.

In my app I list all of the customers in the shop, and ideally I'd like to display this metafield within the list as well.

Ex. First Name, Last Name, Address, Binary Metafield, etc


I obviously have the /customers.json GET working properly with all customer info, now I'm working on the metafields.

How could I grab this metafield for each customer, without making x # of requests (depending on how many customers)?

I hope this isn't an extremely simple solution, but I can't think of any way around the API limit for this. 
I've just started using the Shopify API (yesterday) so I am a bit new at this.

 

Thanks HunkyBill!

0 Likes
Shopify Expert
3943 16 330

You get 250 customers per API call. for each customer, add a metafield. 

simple. 

You can modify the theme to display the metafield values too, in the customer Liquid files. 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Excursionist
28 1 4

Sorry, I meant I need to GRAB that metafield value for each customer in the API.

My original thought - grab customers.json , for each customer in there, grab the id and send another request to Shopify for metafields.json with that user id. 

That should work technically, but if there are 40+ customers I'm going to hit the limit quickly.

0 Likes
Shopify Expert
3943 16 330

You can GET 250 customers in one API call. You won't hit the limit if you page through them like that. And even if you did throw 40 calls out (10,000 customers later).. you still get 2/second. About the API limits... there is a ton of code out there about how to deal with limits in any language except probably COBOL... 

So get 250 customers at a time, and deal with their metafields... and if you hit the limit... big deal.. you wait a 0.5 seconds to make your next API call... 

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
1 Like
Excursionist
28 1 4

Wonderful. Thanks I'll try it out.

Bad pseudocode below - 

Would something like this work (away from pc at the moment):
 

GET customers.json (lets say all 250 customers) {

for each customer in customer.json {

GET metafields.json?metafield[owner_id]=user.id&metafield[owner_resource]=customer {

return data;

}
}

 

0 Likes
Shopify Expert
3943 16 330

yes... that will work fine... 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Shopify Partner
2 0 0

If I understand correctly, I should be able to get up to 250 product metafields with this call:

admin/metafields.json?metafield[owner_resource]=product

However, I get this as a response: (metafields do exist for products)

 {"metafields":[]}

0 Likes
Shopify Expert
3943 16 330

I think you're better off getting a product, and asking for all it's metafields. Asking for metafields that have an owner is kind of chaotic. I think that only works if you also provide an ID. 

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Tourist
9 0 2

I would say something like this should work:

/admin/metafields.json?metafield[owner_resource]=product

This way you only request resources for product and you could even make namespace required for example. Or just providing a list of resource IDs (products IDs for example) would work as well, I guess. Al long as you don't have to download all metafields for each resource one at a time would work for me :)

Improved Google Shopping Feed App: https://apps.shopify.com/simple-google-shopping-feed
1 Like
Shopify Partner
2 0 0

Dennis, that did not work for me.  Note my previous post.  Results were empty.

0 Likes