ProductUpdate BUG - Create an update metafield doesn't work

Solved

ProductUpdate BUG - Create an update metafield doesn't work

tonyricher
Shopify Partner
7 0 1

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?

Accepted Solution (1)

BSSCommerce-B2B
Shopify Partner
565 114 137

This is an accepted solution.

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.

If our suggestions are useful, please let us know by giving it a like, marking it as a solution.


B2B Solution & Custom Pricing |BSS: B2B Portal, Quote, Net 30 | BSS: B2B Login Lock Hide Price


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency

View solution in original post

Replies 3 (3)

BSSCommerce-B2B
Shopify Partner
565 114 137

This is an accepted solution.

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.

If our suggestions are useful, please let us know by giving it a like, marking it as a solution.


B2B Solution & Custom Pricing |BSS: B2B Portal, Quote, Net 30 | BSS: B2B Login Lock Hide Price


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency
tonyricher
Shopify Partner
7 0 1

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

Thank you 🙂

const variables = {
        input: {
            id: product.id,
            "metafields": [
                {
                    "namespace": "custom",
                    "key": "emplacement",
                    "id": "gid://shopify/Metafield/45831948927303",
                    "type": "single_line_text_field",
                    "value": value
                }
            ]
        }
    };
BSSCommerce-B2B
Shopify Partner
565 114 137

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

If our suggestions are useful, please let us know by giving it a like, marking it as a solution.


B2B Solution & Custom Pricing |BSS: B2B Portal, Quote, Net 30 | BSS: B2B Login Lock Hide Price


Need help from our expert? Kindly share your request with us via community@bsscommerce.com


BSS Commerce - Full-service eCommerce Agency