What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Updating Product Metafields with the GraphQL API

Updating Product Metafields with the GraphQL API

wozzakeeps
Shopify Partner
2 0 1

I'm trying to update two product metafields using the GraphQL API.

 

The metafields were created through the Shopify Admin Custom Data section with Content Type 'Single line text'.

 

The mutation I send looks like this:

 

 

mutation {
    productUpdate (input: {
      id: "gid://shopify/Product/1",
      metafields: [
        {
          id: "gid://shopify/Metafield/1",
          value: "Value1"
        },
        {
          id: "gid://shopify/Metafield/2",
          value: "Value2"
        }
      ]
    }) {
      product {
        id
        metafields(first: 10) {
          edges {
            node {
              id
              namespace
              key
              value
            }
          }
        }
      }
    }
  }

(Note: I changed the IDs and values above before posting here)

 

The request returns 200 but the Metafields do not get updated.

 

The response looks like this:

 

 

 

{"id":"gid://shopify/Product/1","metafields":{"edges":[]}}

 

 

Any idea where I'm going wrong?  Thanks

 

Side note:

I noticed that if I change the metafields ID to something random, the request still returns 200.  It's like the metafields property of the mutation is being ignored.

 

Additional info:

  • the metafields are not private metafields
  • I'm using GraphQL API version 2023-04
  • the token I'm using has the read_products and write_products permissions
Reply 1 (1)

wozzakeeps
Shopify Partner
2 0 1

I observed that the userErrors states that the namespace, key and type could not be blank.

 

After adding these fields, the update was successful, although the docs state the fields are optional when updating a metafield in the following articles:

 

I think that either the docs are wrong or the API has a bug.