Graphql Query syntax error on metafield list type

Graphql Query syntax error on metafield list type

siljesch
Shopify Partner
4 0 0

I'm recieving a syntax error when trying to update a metafield created in the shopify admin on productCreate mutation. I have tried formatting the value in every way imaginable, and still recieves an error.

 

This is my mutation:

`mutation {
      productCreate(input: {
        title: "example title",
        handle: "example-title",
        descriptionHtml: "just an example", 
        productType: "my type", 
        tags: ["tag1,tag2"],
        variants:{
          price: "100",
          sku: "123",
        },
        metafields: [
          {
            id: "gid://shopify/Metafield/<id>",
            namespace: "custom",
            key: "key_example",
            type: "list.single_line_text_field",
            value: "[\"test1\",\"test2\"]"
          }
        ]
      }) {
        product {
          id
          variants(first:1){
            edges{
              node{
                id
              }
            }
          }
        }
        userErrors {
          message
          field
        }
      }
    }`

And this is the error I recieve:

GraphqlQueryError: syntax error, unexpected STRING (","), expecting COLON at [19, 28]

 

Also after trying to format the value like this:

value: "['test1','test2']"

I get a response on the userErrors:

{"product":null,"userErrors":[{"message":"Value is invalid JSON: unexpected token at ''test1','test2']'.","field":["metafields","0","value"]}]}

 

Is there anyone that have met the same problem, or is a graphql expert that can help me? 😊

 

Replies 3 (3)

ShopifyDevSup
Shopify Staff
1453 238 508

Hey @siljesch , thanks for sharing this! 

 

Testing on my end here, I was not able to replicate the exact error you are getting, however I was able to get it to work with the metafield values exactly as you have provided them there. 

 

The issue I encountered was that when creating a new product, the metafield id needs to be blank. Once I removed that, it worked just fine. 

 

metafields: [
               {
                   namespace: "custom"
                   key: "key_example"
                   type: "list.single_line_text_field"
                   value: "[\"test1\",\"test2\"]"
               }
           ]

Hope that helps 

 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

siljesch
Shopify Partner
4 0 0

Hi, thanks for your reply!
I removed the id, however I am still getting the same Graphql error:


GraphqlQueryError: syntax error, unexpected STRING (","), expecting COLON at [23, 28]

It almost seems as if it's unable to read the JSON string array properly.

ShopifyDevSup
Shopify Staff
1453 238 508

Hey @siljesch

 

Thanks for that. In this case now it seems to be a syntax error. You an use a tool like Postman that can help narrow down incorrect syntax. 

Once that's cleared up, if you get the invalid json error again, I would look in to seeing if you have a metafield definition set up for this field. If so, I would check that there aren't any specific validation settings set up. 

 

Hope that helps, 

 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog