Hi.
I have allocated a lineUID to an undefined metafield using APP in the shop.
I would like to get that lineUID via API, but I can’t get the meta field via custom app.
Please let me know how I can get it.
Which API are you using? Also, which flavor are you using - GraphQl or Rest?
For Admin API using REST it is easy. You can use it with custom app too and it should be available in the current stable realease 2022-07. Check this page: https://shopify.dev/api/admin-rest/2022-07/resources/metafield
For Admin API, GraphQL metafields are currently not available in stable or release candidate. However, if you are brave to use the unstable version - metafields are available. Check here - https://shopify.dev/api/admin-graphql/unstable/queries/metafields
Hope this helps
Thank you for your response.
I am using RESTAPI. However, I am unable to get metafield data.
What is the cause of not being able to retrieve metafield data?
Do I need to configure it by any chance?
Below is what we used to get the data. Please refer to the following.
/admin/api/2022-07/customers/5688291819658.json?fields=id,metafield,created_at
Hi @LTV-x
Sure, the REST API for customer resource doesn’t have metafields for some reason. However, if you use the API I pointed out in my first reply, the Metafields API, you should be able to retrieve the customer’s metafields.
Here is the endpoint FYR → /admin/api/2022-07/metafields.json?metafield[owner_id]=<CUSTOMER_ID>&metafield[owner_resource]=customer
Also make sure the customer has metafields, otherwise, the response will always be empty!!
PS
(Also just so you know, the GraphQL 2022-07 API does have metafields as well if you want to use it instead)
Hope this helps.
Hi@Mrngodi
Thank you very much for your reply
The following two methods are used to obtain data, but a new problem is that only one piece of data can be obtained at a time.
Please provide instructions on how to obtain multiple pieces of data.
[REST Admin API (Customer)]
/admin/api/2022-07/customers//metafields.json
[REST Admin API (Metafields)]
/admin/api/2022-07/metafields.json? metafield[owner_id]=&metafield[owner_resource]=customer
Thank you
Hi @LTV-x
No problems. I don’t understand what you mean by multiple pieces of data but if your problem is to get metafields for a given customer, I will advice you to use the metafield api
FYR → /admin/api/2022-07/metafields.json?metafield[owner_id]=<CUSTOMER_ID>&metafield[owner_resource]=customer
Make sure you replace the <CUSTOMER_ID> with the actual customer ID
Finally, am sure you know REST APIs work mostly with a single resource. So if you want to be able to fetch data from multiple resources at once, it’s advisable to migrate to GraphQL APIs.
Hope this helps
Thanks @LTV-x
Enjoy!