Solved

Clearing Metafield Data on Specific Product with GraphQL

stats_marketing
Shopify Partner
25 3 12

I need to "clear" values on specific MetaFields with Type "single_line_text_field" but only on specific products using the GraphQL API.

As I understand it we cannot send a blank value when running the `mutation metafieldsSet`, as I initially tried this but it won't take it.

If I try `metafieldDelete` mutation I am afraid that it will delete the MetaField everywhere.

I simply need to clear it on a specific set of Products/Product.

Any way to do this, as I am not seeing any way of doing this with the API?

Accepted Solution (1)

Liam
Shopify Staff
2731 302 782

This is an accepted solution.

Hi again,

 

I've looked into this more and it appears the metafieldDelete mutation will clear just the value of the specified metafield, but it won't delete the value of every instance of the metafield. 

 

The metafieldDefinitionDelete mutation will remove the metafield fully from the store. 

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

View solution in original post

Replies 3 (3)

Liam
Shopify Staff
2731 302 782

Hi Stats_marketing,

 

Just to confirm, you'd like the same ability that existing in the admin where there's an option to clear a products metafield value, but just via the API?

 

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

samuel_webster_
Shopify Partner
5 0 1

I would like this! 

Liam
Shopify Staff
2731 302 782

This is an accepted solution.

Hi again,

 

I've looked into this more and it appears the metafieldDelete mutation will clear just the value of the specified metafield, but it won't delete the value of every instance of the metafield. 

 

The metafieldDefinitionDelete mutation will remove the metafield fully from the store. 

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