Issue Updating Metafield Value via Shopify GraphQL Admin API

Issue Updating Metafield Value via Shopify GraphQL Admin API

Sufi879
Shopify Partner
2 0 0

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?

Sufi879_0-1724239341467.png

 

Replies 2 (2)

BSSCommerce-B2B
Shopify Partner
1505 431 487

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)

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

Sufi879
Shopify Partner
2 0 0

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
Sufi879_0-1724311193911.png