Eorr with Metafield Definition type

Hi there,

When I try to create a metafield definition with the type set to “money,” it always reports that the key already exists. I’ve checked the list of metafield definitions within that namespace ($app:namespace), but the key I want to create doesn’t actually exist, and our namespace format is $app:namespace

Thanks in advance! this is preventing some of our merchants from performing standard customer support

Mutation:

{
"query": "mutation CreateMetafieldDefinition($definition: MetafieldDefinitionInput!) { metafieldDefinitionCreate(definition: $definition) { createdDefinition { id name } userErrors { field message code } } }",
"variables": {
"definition": {
"name": "Money Format",
"namespace": "$app:namespace",
"key": "shop_currency",
"access": {
"admin": "PUBLIC_READ",
"storefront": "PUBLIC_READ"
},
"type": "money",
"ownerType": "SHOP"
}
}
}

Does the mutation work if you use a namespace without $ eg: test_namespace?

1 Like

Hi Liam,

I tried creating a definition with a namespace without $e.g:test_namespace, but it didn’t work, and it returned the error: Setting access controls on a definition under this namespace is not permitted.

Is there any update for this? I have the same issue :roll_eyes:

The issue you’re experiencing may be related to how the $app: namespace is resolved by Shopify. Specifically, the $app: prefix is translated into a fully resolved reserved namespace by the API layer, with the format:

app–{your-app-id}–{some-namespace}

Here’s a breakdown of how this works:

  • app: This prefix signifies that the namespace belongs to an app.

  • your-app-id: This is the API client ID associated with your app.

  • some-namespace: This is the custom namespace you’ve chosen, e.g., namespace in your case.

For example, if your API client ID is 123456, your resolved namespace will look like this:
app--123456--namespace

Key Points:

When creating or updating metafields via the API, always use $app:namespace in your requests. Even if the namespace appears valid (e.g., $app:namespace), the error could occur if there’s already a conflicting key under the fully resolved namespace (app–{your-app-id}–namespace).

Next Steps:

  • Confirm that no conflicting metafield definition with the key shop_currency exists under the resolved namespace (app–{your-app-id}–namespace).

  • Use the metafieldDefinitions query to retrieve all definitions in this namespace for verification.

  • If no conflict exists, retry the creation request with the same parameters.

I have checked the metafield definitions with the fully resolved namespace (e.g., app–{your-app-id}–namespace) and also with $app:namespace, but the key I want to create does not appear. However, when I perform the mutation, I still encounter the error: Definition type does not support migration of existing metafields. Could it be due to the type: money? Please verify this for me.

Fetch Metafield Definitions
Use the following query to fetch all metafield definitions for the shop:

query MyQuery {
  metafieldDefinitions(ownerType: SHOP, first: 10) {
    nodes {
      key
      id
      name
      description
    }
  }
}

Check for Existing Definition
Review the result to confirm if it contains a definition with the key "shop_currency".

Delete Existing Definition (If Necessary)
If the definition exists and you want to delete it, use the following mutation:

mutation DeleteMetafieldDefinition($id: ID!, $deleteAllAssociatedMetafields: Boolean!) {
  metafieldDefinitionDelete(id: $id, deleteAllAssociatedMetafields: $deleteAllAssociatedMetafields) {
    deletedDefinitionId
    userErrors {
      field
      message
      code
    }
  }
}

Variables:

{
  "id": "gid://shopify/MetafieldDefinition/123456789",
  "deleteAllAssociatedMetafields": true
}

Create New Metafield Definition
If you want to create a new metafield definition with the key "shop_currency", use the following mutation:

mutation CreateMetafieldDefinition($definition: MetafieldDefinitionInput!) {
  metafieldDefinitionCreate(definition: $definition) {
    createdDefinition {
      id
      name
    }
    userErrors {
      field
      message
      code
    }
  }
}

Variables:

{
  "definition": {
    "name": "Money Format",
    "namespace": "$app:namespace",
    "key": "shop_currency",
    "access": {
      "admin": "PUBLIC_READ",
      "storefront": "PUBLIC_READ"
    },
    "type": "money",
    "ownerType": "SHOP"
  }
}

I have used these queries and confirmed that all of them are working correctly. If there’s anything further needed from my side, please let me know.

1 Like