I have created a few metafield in my development store under but when try to retrieve the list of all the metafields using the mentioned Metafield API, it doesn’t show any of it.
Could you please help me here?
I have created a few metafield in my development store under but when try to retrieve the list of all the metafields using the mentioned Metafield API, it doesn’t show any of it.
Could you please help me here?
Hello Yagnesh97,
Let me help you out here.
It really depends on how you initially created the metafield.
Was it done through the Admin Rest API? If so can you provide a snippet on how you did it?
The reason why I ask is because metafields are always attached to a particular resource.
If you didn’t provide a resource when creating then it defaults to the Shop resource.
To retrieve all metafields attached to the Shop resource you can do so by sending a request to
https://your-development-store.myshopify.com/admin/api/2022-01/metafields.json
Let me know how you created your metafield and I’ll be happy to provide assistance.
Hey @lastiri ,
I created a Metafield named “highlights” under Settings > Metafields > Add Definition.
But when I query the below cURL request it doesn’t show up.
curl -X GET "https://your-development-store.myshopify.com/admin/api/2021-10/metafields.json" \
-H "X-Shopify-Access-Token: {access_token}"
Getting the below response from the API.
{
"metafields": []
}
Hello @yagnesh97 ,
Thanks for the clarification.
Ok, so what you have created by going through the admin is a Metafield Definition within the owner type Product.
Now that the metafield definition is created, it is time to add the corresponding metafield to each product.
You have two options to do that.
Send a request to create a new metafield for a Product resource. Notice that I provide the product_id as part of the URL.
With the metafield created under the product. You also have two options to retrieve the metafields for a particular product.
https://your-development-store.myshopify.com/admin/api/2021-10/metafields.json
With Query params:
metafield[owner_resource] = product
metafield[owner_id] = <your_product_id>
https://your-development-store.myshopify.com/admin/api/2021-10/products/

Hopefully that clarifies your question. Let me know if you have any following questions.
Rafa | Shopify
------------------------------------------------------------------------------------------------------------------------------------------
- Was my reply helpful? Click **Like** to let me know!
- Was your question answered? Mark it as an **Accepted Solution**
- To learn more visit the [Shopify Help Center](https://bit.ly/3itITEC) or the [Shopify Blog](https://bit.ly/3izVw0T)
Hey @lastiri ,
Thanks a lot for sharing the solution. I appreciate your efforts.
Hi @lastiri
Having trouble setting and retrieving metafield values.
Am I understanding the behavior of Metafields when I say
I wanted to programatically know if a product is sold for the first time ever and decided to create a metafield
{
"key":"ever_sold",
"type:boolean"
}
and keeping it true after one is sold otherwise false or empty.
I manually filled this field to a product on UI and did
GET: products/{product_id}/metafiels.json
then saw
"id":22414790557925
So I did
PUT: products/{product_id}/metafiels/22414790557925.json
{"metafiled":{"value":true}}
to all the products and they all came through.
22414790557925 won’t be listed up with
GET: products/{product_id}/metafiels.json
but if I do
GET: products/{product_id}/metafiels/22414790557925.json
it gave me back
"key":"ever_sold"
"value":true
"type:"boolean"
@lastiri Is there a way to retrieve all metafields without any product or source ? All i want to do is retrieve entire metafields which shop is using or created. That is all. I can’t request for all products individually to see all metafields.