Bug on updating metafields?

Louise_Elmose_H
Shopify Partner
78 2 21

Hi,

I use the graphql productUpdate mutation to update a product as well as the product variants and metafields.

In general this works as expected, I can update metafield values as I want to. But I run into problems when I want to reset a metafield, i.e. when I set the metafield value to null.

If a metafield value before was e.g. "Apple" and I want to set it to null, nothing happens, the value is still "Apple". If I try to set it to '' or ' ' it does not work either. '-' works, but it is not a pretty solution.

I also tried not including the metafield in the metafield list, but the value of the metafield is still "Apple". 

So to me it seems to be a bug? 

Thanks,

-Louise

Reply 1 (1)

Dave_Pelletier
Shopify Staff (Retired)
27 3 5

Hi Louise!

To delete a metafield you need to use a different mutation called metafieldDelete:

https://shopify.dev/api/admin-graphql/2021-10/mutations/metafieldDelete

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