ProductUpdate BUG - Create an update metafield doesn't work

Hello,

I’m having a problem with the productUpdate API in graphQL.

I’ve created a metafield to enter the location of my product. (Namespace: “custom”, key: “location”);

I’m trying to do this via the shopify-graphiql-app test console. I don’t get any errors, but nothing goes up on my product.

It’s as if the API doesn’t take my request into account.

I’m on the GraphQL 2024-04 API. Here’s my code:

mutation updateProductMetafields($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      id
      metafields(first: 10) {
        edges {
          node {
            id
            namespace
            key
            value
          }
        }
      }
    }
    userErrors {
      message
      field
    }
  }
}

Variables :

{
  "input": {
    "id": "gid://shopify/Product/8865022411079",
    "metafields": [
      {
        "id": "gid://shopify/Metafield/45831948927303",
        "type": "list.single_line_text_field",
        "value": "Castafiore"
      }
    ]
  }
}

The id corresponds to my desired metafield. Here’s an example, done by hand on a product and fetching the same product.

{
"node": {
"id": "gid://shopify/Metafield/45831948927303",
"namespace": "custom",
"key": "emplacement",
"value": "France"
}
}

I tested several things before asking you.
There’s no problem with productCreate but productUpdate bug.

Any ideas?

Hi @tonyricher ,

As I see in variables, your metafield type is list.single_line_text_field but your value is Castafiore just a text. I think you should change type into single_line_text_field or remove it from variables because that field is optional when updating.

In case you want your metafield to be a list, and you are pushing more text into metafield, you need to modify the value from “France” to “["France","Castafiore"]”

Hope you can fix the issue soon.

That was exactly my problem. I found the solution a few minutes later.

Thank you :slightly_smiling_face:

const variables = {
        input: {
            id: product.id,
            "metafields": [
                {
                    "namespace": "custom",
                    "key": "emplacement",
                    "id": "gid://shopify/Metafield/45831948927303",
                    "type": "single_line_text_field",
                    "value": value
                }
            ]
        }
    };
1 Like

Glad to hear that. Finding out the solution by self is such a great feeling :grin: