Product Metafields don't update with GraphiQL

Topic summary

Users are encountering issues updating public product metafields via GraphQL’s productUpdate mutation, receiving errors like “Key must be unique within this namespace on this resource” despite successful API responses.

Key Technical Requirements Identified:

  • Must include valueType parameter (e.g., “INTEGER”, “STRING”) in the mutation
  • Must use the metafield’s actual id (e.g., “gid://shopify/Metafield/XXX”) rather than just namespace/key as the identifier
  • Requires appropriate API access permissions/scopes

Common Issues & Solutions:

  • Permission errors: Resolved by reinstalling the Shopify GraphiQL App or verifying user account permissions
  • Value conflicts: Title_tag metafield cannot have the same value as the product’s title
  • Documentation gap: Official tutorials only cover updating private metafields, not public ones, causing confusion

Current Status:
Some users successfully updated metafields after correcting the mutation structure and permissions. However, the “Key must be unique” error persists for others in the latest API version, suggesting the issue remains partially unresolved. The lack of clear documentation for public metafield updates continues to be a pain point.

Summarized with AI on November 24. AI used: claude-sonnet-4-5-20250929.

Hi there! I am trying to change metafields data for any given product.

The request succeeds but data isn’t updated.

I have attached a photo to illustrate.

Here’s the text version of this code:

mutation {
  productUpdate(input: {
  id: "gid://shopify/Product/8441259336",
    metafields: [
      {
        namespace: "global",
        key: "wish_count",
        value: "550",
      }
    ]
  }) {
    product {
      metafield(namespace: "global", key: "wish_count") {
         id
          namespace
          key
          value   
      }
    }
  }
}

Hi Arkadi,

It looks like the issue you are running into here is that your mutation is missing the valueType parameter in the input. In this case, you will most likely want to set this to “INTEGER”.

In the future, I recommend that you try running these mutations in the Shopify GraphiQL App and including the userErrors return field to get the most amount of feedback. For your mutation, including the userErrors would have given you the information to help fix the issue. I’ve included an example below.

mutation productUpdate($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      metafield(namespace: "global", key: "wish_count") {
        id
        namespace
        key
        value
      }
    }
    userErrors {
      field
      message
    }
  }
}

Variables:

{
  "input": {
  	"id": "gid://shopify/Product/8441259336",
    "metafields":  {
        "namespace": "global",
        "key": "wish_count",
        "value": "550",
        "valueType": "INTEGER"
      }
  }
}

If you run into any other issues, please reach out!

Thanks ntan for your quick answer

Tried it too, still does not work.

we get similar response even when adding the valyeType as you suggested

meaybe its a matter of permissions? the get request works well but we cannot update, create or delete

and this is the reply we get

{
“data”: {
“productUpdate”: {
“product”: {
“metafield”: {
“id”: “gid://shopify/Metafield/11975849934931”,
“namespace”: “global”,
“key”: “wish_count”,
“value”: “549”
}
},
“userErrors”: [
{
“field”: [
“metafields”,
“0”,
“key”
],
“message”: “Key must be unique within this namespace on this resource”
}
]
}
},

Hi rchenx,

I realize now that what you’re trying to do is update the value of an existing metafield on a product, which cannot actually be done with the mutation we are using here. Instead, we should be using the privateMetafieldUpsert mutation instead. Take a look at the tutorial I have linked here. That should give you the information you need to update the product.

I recognize that this is a bit confusing and not very intuitive, so I will speak to the team here about what we can do to make the documentation clearer on how to handle this use case. Please let me know if you run into any other issues.

Hello ntan,

We are interested in changing PUBLIC metafield and not private metafield becouse we need the shopify liquid code to utize those values

how that should be addressed?

Best

Ronen

I would also like to add that in this tutorial:

https://shopify.dev/tutorials/manage-metafields-with-graphql-admin-api

updating metafields only exists for private metafields.

How about the public ones too? we need to access those fields in shopify liquid… We can’t use private metafields.

the POST of new public metafields works, but we need to UPDATE as well. When we try to do this with the public metafields this is thew error returned:

“Key must be unique within this namespace on this resource”.

Hi folks,

My mistake for suggesting the privateMetafieldUpsert mutation. You are correct in that it is the wrong thing to be using here. Instead, we should be using the productUpdate mutation as you originally thought, except instead of passing in the key as the identifier, we should use the actual id of the metafield itself. I have included a sample of what the mutation should look like below:

mutation productUpdate($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      metafield(namespace: "global", key: "wish_count") {
        id
        namespace
        key
        value
      }
    }
    userErrors {
      field
      message
    }
  }

Variables:

{
  "input": {
     "id": "gid://shopify/Product/8441259336",
        "metafields":  {
           "id": "gid://shopify/Metafield/11975849934931",
           "value": "550",
           "valueType": "INTEGER"
     }
  }
}

Please let me know if this works for you.

5 Likes

I get a “ProductUpdate access denied” when trying your method.

Is it possible to update public product metafield?

Access denied typically indicates that your API credentials don’t have the access scope permissions to perform the operation. If you edit the app permissions in the Shopify web admin and reauth your app then it should work.

I got this error using the Shopify GraphiQL App from my shop page.

(At the end I don’t mean to use it through an app but directly in a lambda function)

So if you go into the Shopify web admin for this shop and go into your logged-in user account. See what permissions are listed there. If you are using the Shopify GraphiQL app then the permissions flow from the logged-in user.

It’s the main root account.

Mind providing a full screen shot of the GraphiQL app query that’s failing?

I just ran this for a ProductVariantUpdate using the GraphiQL app in my test store. It worked fine. See below. I didn’t have an exiting product with a defined metafield so it was against a variant child, but seemed to go okay. And you’ve verified that this particular Shopify account has the appropriate permissions? I know you said that it’s the root account, but double-checking might not hurt!

Well, you were right! Thx for insisting. :slightly_smiling_face:

I wasn’t able to review full rights of the application (or at least they were misleading) but eventually I reinstalled it and it worked.

Side note: it seems to me that the example here: https://shopify.dev/tutorials/manage-metafields-with-graphql-admin-api#updating-the-owning-resource

Lack with the field

“id”: “gid://shopify/Metafield/XXX”,

Otherwise you get a: “message”: “Key must be unique within this namespace on this resource”

hey mate, I’m sending this mutation:

mutation {
  productUpdate(input: {
    id: "gid://shopify/Product/6653113303204",
    title: "zinc test",
    metafields: [
      {
        namespace: "global",
        key: "title_tag",
        value: "zinc test",
        valueType: STRING
      }
    ]
  }) {
    product {
      id
      metafields(first: 10, after: null) {
        edges {
          node {
            key
            namespace
            value
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

and getting this response:

{
  "data": {
    "productUpdate": {
      "product": {
        "id": "gid:\/\/shopify\/Product\/6653113303204",
        "metafields": {
          "edges": []
        }
      },
      "userErrors": []
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 22,
      "actualQueryCost": 12,
      "throttleStatus": {
        "maximumAvailable": 1000.0,
        "currentlyAvailable": 988,
        "restoreRate": 50.0
      }
    }
  }
}

I’m trying to create the metafield

Hi @tomasdelaveau

In your query, metafield valueType is not in quotes. It should be “STRING” instead of STRING.

Could that help?

Hey @Iipa , that’s incorrect. It has to be without quotes. The problem was that the gobal title tag can’t have the same value as the product’s title.

in the latest api version namespace and key fields are mandatory, so I continue to get

message": “Key must be unique within this namespace on this resource”
. Unable to update public metafield using productUpdate mutant.

{
“query”: “mutation productUpdate($input: ProductInput!) { productUpdate(input: $input) { product { id handle } userErrors { field message } }}”,
“variables”: {
“input”: {
“id”: “gid://shopify/Product/XXXXX967638075”,
“metafields”:
{
“id”: “gid://shopify/Metafield/XXXXX2443”,
“namespace”:“my_fields”,
“key”:“product_extra_info”,
“type”:“json” ,
“value”: “{\r\n "$id": "1",\r\n "colour": "Rose Gold"}”
} } }}