Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Add Defined Metafields Through API

Add Defined Metafields Through API

Yoseo2024
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)

Liam
Community Manager
3108 344 889

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 Shopify.dev or the Shopify Web Design and Development Blog

Yoseo2024
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?