Issue Updating Metafield Value via Shopify GraphQL Admin API

I’m using the Shopify GraphQL Admin API to update a metafield, but I’m encountering an issue where the value doesn’t get updated if the metafield already has an existing value. Has anyone experienced this or know how to resolve it?

Hi @Sufi879 ,

Can you try again with a different return in your query? As I can see, you are returning only one metafield, try this instead and find you metafield id in response.

metafields(first: 10) {
        edges {
          node {
            id
            namespace
            key
            value
          }
        }
      }

And let I see the result so I can detect more about your issue (if the metafield you are trying to update not shown)

Hi @BSSCommerce-B2B ,

Actually I’m returning the metafield related to this product

mutation {
productUpdate(input: {id: “gid://shopify/Product/7625814081647”, metafields: [
{
id: “gid://shopify/Metafield/34199076975”,
namespace: “custom”,
key: “product_group”,
value: “X”
}
]}) {
product {
id
metafield(namespace:“custom”,key:“product_group”)
{
value
}
}
}
}
and I have also check the value from store front it is not updating if there is an existing value in the field it only updates when the field is empty