What's your biggest current challenge? Have your say in Community Polls along the right column.

ProductUpdate BUG - Create an update metafield doesn't work

Solved

ProductUpdate BUG - Create an update metafield doesn't work

tonyricher
Shopify Partner
9 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
1969 564 566

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.

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

View solution in original post

Replies 3 (3)

BSSCommerce-B2B
Shopify Partner
1969 564 566

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.

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

tonyricher
Shopify Partner
9 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
1969 564 566

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

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