Set custom metadata fields on product via Rest API?

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

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?

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

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

1 Like

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 :slightly_smiling_face:

1 Like