Getting customer metafields from the api

Kevin_Ruscoe
Shopify Partner
5 0 6

Hello, I've managed to use the PUT and POST requests to add metafields to my customers. However, after the initial insertion of the data, i cannot update the metafields because i need to pass the ID of the metafield to update. However, I can't get the actually metafields using the shopify API.

I'm using https://stuff:stuff@domain/admin/customers/100.json to get the json data of a custom, but the metafields are missing. However, in liquid if i use {{ customer.metafields.namespace }} the data is present.

Any ideas?

Replies 2 (2)

HunkyBill
Shopify Expert
4846 60 552

You never get metafield resources when you request a parent resource like a customer, product or variant. You have to request them with a separate API call. So when you request a customer resource you can subsequently request the metafield resources attached to it. Try that and you'll see your metafields using API calls.

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

Kevin_Ruscoe
Shopify Partner
5 0 6

Yeah, I just found this out! I'm now using /admin/metafields.json?

metafield[owner_id]=user_id&metafield[owner_resource]=customer

and that's showing the ID's of the resources now. This wasn't very clear in the API docs, but hopefully someone stumbling across this thread will find it useful.