Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Hi Team,
I want to create some custom fields into the Shopify Admin application. I read about metafields in the Shopify API documentation. But somehow was not able to understand how to use metafields and where it will get reflected.
I tried to add metafields to products resource and the API call was successful. I was expecting that the new fields which I added would reflect on the Add Products page. But unfortunately it did not appear.
So can anyone please help me understand how to go about these metafields?
Hi, you can't view metafields directly. But you can access them using liquid variables.
For example, you might want to add additional information to orders or products such as hotlinks which should be displayed to the customer on their account page. You can edit the customer.account template and display those metafields, e.g.:
{% for line_item in order.line_items %} {% if line_item.fulfillment and line_item.product.metafields.yournamespace.yourkey %} {% for metafield in line_item.product.metafields.yournamespace.yourkey %} <tr> <td colspan="5"> <a href="{{ metafield.href }}" target="_blank"> {{ metafield.href_text }} </a> </td> </tr> {% endfor %} {% endif %} {% endfor %}
I want to achieve this via the APIs. Is this possible??
Hey @agaonkar , you will need to use a plugin to view and edit the metafields you've assigned in the Add Product page. Metafields Guru is the popular one: https://apps.shopify.com/metafields-editor-2?utm_campaign=installed&utm_content=contextual&utm_mediu...
Could you please let me know the steps to achieve the same via APIs.
For example,
Create a new meta field on the Products page
Add some value in that field
View the newly added metafield on the Shopify Admin UI
Thanks,
Ambika
Hi,
Any pointers will be highly appreciated.
Basically I would like to know how to use the Metafields API?
These documents contains the Metafields API information:
https://help.shopify.com/en/api/guides/metafields/admin-api-metafields
https://help.shopify.com/en/api/graphql-admin-api/examples/product#creating-products
https://help.shopify.com/en/api/reference/metafield#create-2019-10
A sample POST product with metafields would look like this:
POST /admin/api/2019-10/products.json //REST
{ "product": { "title": "Burton Custom Freestyle 151", "body_html": "<strong>Good snowboard!</strong>", "vendor": "Burton", "product_type": "Snowboard", "tags": "Barnes & Noble, John's Fav, \"Big Air\"", "metafields": [ { "key": "wax", "value": "Turtle Wax", "value_type": "STRING", "namespace": "snowboard_care_instructions" } [ } }
//graphQL
mutation($input: ProductInput!) { productUpdate(input: $input) { product {
id,
title, metafields(first: 100) { edges { node { id namespace key value } } } } } }
Once you've uploaded the product with metafields via the API you will need to use or create an app to view/edit them (see my previous link for such an app).
Thanks alot for the solution. I am able to proceed with metafields.