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?