Add Defined Metafields Through API

Add Defined Metafields Through API

Shopify Partner
4 0 0

I want to add metafields as specifications for the products in the store. 

I added metafields as below


namespace: "specs", 

key : [name of spec (ex. screen resolution)],

value: [value of screen resolution]


When I did this I was able to display the specifications in the product page as


{% for metafield in product.metafields.specs %}
<p>{{ metafield.first }}: {{ metafield.last }}</p>
{% endfor %}


but I was not able to use them for filtering because they were not defined. And I was unable to define them through the Shopify Admin because they had specials chars (spaces). 

Then I tried to add the key as a handle, with dashed instead of spaces and no more brackets, and added one more field to the metafields as description - that was the name of the spec with spaces and so on - however I can't display the metafield.description value. 


Any idea how can I add the metafields already defined, or to display the description? 


Thank you guys! 

Replies 2 (2)

Shopify Staff
2807 310 805

Hi Yoseo2024,


 If there are no special characters being used, are the values of the metafields appearing as expected?

Liam | Developer Advocate @ 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 or the Shopify Web Design and Development Blog

Shopify Partner
4 0 0

Hi Liam, 


I tried that, the metafields are still not appearing as Defined already. 

I guess what I'm actually looking for is like a guide or how are Definitions and Metafields work. Can I add one definition and more metafields that are somehow related to that definition and more products?