Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Clearing Metafield Data on Specific Product with GraphQL

Solved

Clearing Metafield Data on Specific Product with GraphQL

stats_marketing
Shopify Partner
26 3 14

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
Community Manager
3108 342 884

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 4 (4)

Liam
Community Manager
3108 342 884

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
Community Manager
3108 342 884

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

THodge
Tourist
8 0 1

To clear values in specific MetaFields of type "single_line_text_field" for certain products using the GraphQL API, you need to set the MetaField value to an empty string for each specific product. This approach ensures that the MetaField is cleared only for the selected products without deleting it globally. Unlike a private haushaltsauflösung in der nähe where you can selectively clear specific items without affecting others, the GraphQL API allows you to clear MetaField values for specific products by setting them to an empty string, ensuring precision and control over which MetaFields are cleared.