New Shopify Certification now available: Liquid Storefronts for Theme Developers

Set custom metadata fields on product via Rest API?

Solved
Rune1
Shopify Partner
4 0 1

Shopify doc on metafields:
https://help.shopify.com/en/manual/custom-data/metafields?st_source=admin&st_campaign=metafields_foo...

As seen in the image the user can add custom metafields to the products, how can I create new products and set metafields? How do I access them? I can not see anything on /product api, is there another api im missing?

2023-04-17 10_14_36-Window.png

Accepted Solution (1)
abhiteshs
Shopify Staff
Shopify Staff
5 3 3

This is an accepted solution.

Yes, this is expected behaviour. Refer to this page to learn how to manage metafields:
https://shopify.dev/docs/apps/custom-data/metafields/manage-metafields

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 3 (3)
Rune1
Shopify Partner
4 0 1

So I figured out how to set the metafield property with put request: {"product":{"id":632910392,"metafields":[{"key":"Colors","value":"newvalue","type":"single_line_text_field","namespace":"custom"}]}}

But if the field has an existing value then I get the following error when i try to update the value.
Key: must be unique within this namespace on this resource

 

abhiteshs
Shopify Staff
Shopify Staff
5 3 3

This is an accepted solution.

Yes, this is expected behaviour. Refer to this page to learn how to manage metafields:
https://shopify.dev/docs/apps/custom-data/metafields/manage-metafields

To learn more visit the Shopify Help Center or the Community Blog.

Rune1
Shopify Partner
4 0 1

Thanks for the reply, it helped me solve my issue. It is not REST but that's fine. I found this graphql mutation to solve my specific case: https://shopify.dev/docs/api/admin-graphql/2023-04/mutations/metafieldsset. For future developers, that could be interested 🙂