Cannot delete app-data metafields

My app stores some data in app-data metafields. When the data is no longer needed (i.e. during uninstall), in attempt to the keep the merchant’s store clean, I would like to be able delete any data in the app-data metafields, and also delete the app-data metafields themselves.

According to the documentation, app-data metafields are created using the metafieldsSet mutation, are owned by the app (or API_PERMISSION enum type), and do not have a definition (unlike metafields for PRODUCT, PRODUCTVARIANT, etc…)

So when I try to delete an app-data metafield using the metafieldsDelete mutation as follows:

mutation deleteAppMF($mf: [MetafieldIdentifierInput!]!) {
  metafieldsDelete(metafields: $mf) {
    deletedMetafields {
      key
      namespace
      ownerId
    }
    userErrors {
      field
      message
    }
  }
},
{
  variables: {
    "mf": [
      {
        "key": {key1}
        "namespace": "$app:{appTitle}",
        "ownerId": {appInstallationId}
      }
    ]
  }
} 

I get the following error:

"metafieldsDelete": {
  "deletedMetafields": [],
  "userErrors": [
    {
      "field": [
        "metafields"
      ],
      "message": "Access to this namespace and key on Metafields for this resource type is not allowed."
    }
  ]
}

I am running this mutation from my local dev GraphiQL web interface (g from shopify CLI) which has the same access scopes as my app. In reviewing the API access scopes, there is no access scope specific to the Metafield object, so I’m puzzled by this error message.

Interestingly enough, the deprecated metafieldDelete mutation (tested with API 2024-10) successfully deletes the app-data metafield by specifying the metafield’s ID (not the ownerId as with an app-data metafield).

Is this a gap with the new metafieldsDelete mutation?

1 Like

Hey Steve,

It does appear you’re doing things correctly, I’ve reached out to the custom data team to look into this further.

Having the same issue right now. Also because we can not delete it entirely, we cannot create a definition with same namespace and key again, and now because I have it on READONLY for Merchants we have a metafield there that is blocked forever.

[
  {
    field: [
      "definition",
    ],
    message: "Definition type does not support migration of existing metafields.",
    code: null,
  },
]

Any updates from the custom data team?

Following up for any updates. Using the deprecated metafieldDelete mutation in the interim as a workaround.

Have asked the relevant team about this one again Steve.

Just to update - our team are working on a fix for this

Thanks for the update. Please let me know if/when you need to test the fix.

The error message “Cannot delete app-data metafields” typically appears in Shopify or other platforms when trying to delete metafields related to app data. Possible reasons include:

  1. Insufficient permissions – Your account or app does not have the required permissions to delete the metafield.
  2. Third-party app control – A third-party app created the metafield, and only that app has the authority to delete it.
  3. Shopify API restrictions – Shopify may prevent direct deletion of certain metafields via API or the admin interface.
  4. Non-deletable metafields – Some metafields can only be updated but not deleted.

Possible Solutions:

  • Check if you have admin permissions.
  • Identify if a third-party app is managing the metafield and try deleting it from within the app.
  • If using the Shopify API, try updating the metafield instead of deleting it.
  • Review Shopify’s documentation (e.g., Shopify Metafields API) to see if the metafield type allows deletion.

Are you facing this issue on Shopify or another platform?

I have the same issue. Hoping for the quick fix!

Will fall back to deprecated metafieldDelete for now as @Steve_Karan suggests.