Clearing Metafields Issue: "Value can't be blank" Error Despite Explicitly Setting Value to ""

Topic summary

A developer is encountering a “Value can’t be blank” error when attempting to clear metafields via Shopify’s GraphQL Admin API (version 2025-04).

The Goal: Remove metafields entirely from products during CSV import by setting their value to an empty string (“”), which according to Shopify documentation should delete the metafield.

Implementation Details:

  • Using Python with the requests library and watchdog for file monitoring
  • Executing a metafieldsSet mutation with value: "" for single_line_text_field type metafields
  • Payload structure includes ownerId, namespace, key, value, and type fields

The Problem: Despite explicitly setting value to “”, the API returns an error instead of deleting the metafield as expected.

Current Status:

  • One other user confirms experiencing the same issue with product metafields
  • A workaround of using a space character (" ") displays as blank but leaves unwanted spacing in the theme
  • No definitive solution has been identified

The discussion remains open with users seeking the correct approach to programmatically clear metafield values without triggering validation errors.

Summarized with AI on October 28. AI used: claude-sonnet-4-5-20250929.

Hi everyone,

I’m experiencing an issue when attempting to clear (delete) metafields using the Shopify GraphQL Admin API (version 2025-04). My goal is to remove the metafield so that after the import the metafield does not exist for that product. According to Shopify’s guidelines, if a metafield’s value is empty, it should be deleted (not just set to an empty string).

I’ve implemented the following approach in Python using the requests library to perform the GraphQL call (along with watchdog to monitor local file changes). For metafields that should be cleared, I explicitly set the value field to an empty string (“”) and execute a mutation designed to clear them:

if clear_fields:
    query_clear = """
    mutation ClearMetafields($metafields: [MetafieldsSetInput!]!) {
      metafieldsSet(metafields: $metafields) {
        metafields {
          key
          namespace
          value
          updatedAt
        }
        userErrors {
          field
          message
        }
      }
    }
    """

My payload for the metafields I want to clear looks like this:

{
  "metafields": [
    {
      "ownerId": "gid://shopify/Product/9722952974604",
      "namespace": "custom",
      "key": "data_spedito_da",
      "value": "",
      "type": "single_line_text_field"
    },
    {
      "ownerId": "gid://shopify/Product/9722952974604",
      "namespace": "custom",
      "key": "data_venduto_da",
      "value": "",
      "type": "single_line_text_field"
    }
    // ... additional fields ...
  ]
}

Despite this, the API always returns an error like:

[{'field': ['metafields', '0', 'value'], 'message': "Value can't be blank."}, ...]

I have verified that the payload is sent exactly as shown (the logging output confirms that the value field is present and set to “”), yet the error persists.

Details:

API Version: 2025-04

Libraries Used: Python requests library for HTTP calls, and watchdog for file monitoring.

Expected Behavior: If a metafield’s value is empty in the CSV import, then that metafield should be deleted. The mutation should delete the metafield (or at least result in its absence), not leave an empty value.

Issue: Instead of deleting the metafield, the API responds with “Value can’t be blank.”

Question:

How can I achieve this? Is there a recommended approach or a required payload modification that allows me to update a metafield so that its value becomes empty (cleared) without deleting the metafield entry entirely? Essentially, how do I pass a value that renders the metafield empty—so that my theme automatically hides empty values—without triggering the “Value can’t be blank” error?

Any insight or guidance would be greatly appreciated. Thanks in advance!

1 Like

I’m seeing this same issue. I can submit anything to update my product single line text metafield, except a blank space.

For me, I’m displaying a date that something will be back in stock and the quantity is 0. So the metafield contains a message with the date the product is expected to be back in stock.

In the actual website section…where I’m displaying the metafield, I noticed if I set the metafield value to say " "…it will display blank…but unfortunately, you will still get that spacing there…so you’re really adding something there, you just can’t see it.

I might end up going down this route.