Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Hey,
I receive an error -
message": "Value is invalid JSON: 434: unexpected token at '{\"Name\": \"Overall Measurements\", \"Value\": \"30\" x 14.5\" (76.2cm x 37cm)\", \"Seq\": \"10\"}, {\"Name\": \"Handles\", \"Value\": \"Shoulder Straps, Top Grab Handle\", \"Seq\": \"60\"}]}'"}],
on the below mutation.
mutation { SKUAKNB135COUNT4:productCreate(input :{title:"Mesh Backpack (AKB135)" metafields:[{value:"""{"Spec": [{"Name": "Overall Measurements", "Value": "30\" x 14.5\" (76.2cm x 37cm)", "Seq": "10"}, {"Name": "Handles", "Value": "Shoulder Straps, Top Grab Handle", "Seq": "60"}]}""" key:"specs" valueType:JSON_STRING namespace:"pdct_custom_fields" }] vendor:"Akona" handle:"AKNB135-product_handle" productType:"Gear Bags" images:[] variants : [] }) { userErrors { field message } product { id } }}
I checked the metafield value and it appears to be a valid json. Can anyone help me on this.
Can you try out pasting your code into the Shopify GraphiQL app and see how it goes? https://shopify.dev/tools/graphiql-admin-api My first guess would be all of the quotation marks and their escaping might be awry.
Hi @Gregarican
Tried that too, get the same error there too.
Also the metafield value has a double quote inside - which is actually defining inch(") and I escaped it. So the value is a valid json it seems.
Thanks!
I would suggest checking the Metafield fields you are passing into your request. I don’t see anything listed as a Seq property in the API docs for example. Here are some screen shots from the GraphQL API docs for Metafields. Namespace, Key, Value, and ValueType are about it.
Hi @Gregarican
Seq is not a part of graphql propery. It's just the value of a metafield. And the metafield type is json_string.
metafields:[{value:"""{"Spec": [{"Name": "Overall Measurements", "Value": "30\" x 14.5\" (76.2cm x 37cm)", "Seq": "10"}, {"Name": "Handles", "Value": "Shoulder Straps, Top Grab Handle", "Seq": "60"}]}""" key:"specs" valueType:JSON_STRING namespace:"pdct_custom_fields" }]
^ is how I defined metafield on graphql mutation
I see that now...sorry I didn't look closely enough at what you were sending. And you're sure that Shopify can accept a complex JSON string as a metafield data type? I honestly have only seen basic data types such as strings. Can you try sending a simple string to see what the outcome would be like in the example in their API documentation?
simple strings will work. It's just that my data is a bit complex 😞
Then that tells us that you apparently cannot have a JSON string data type. An alternative would be packing everything you need into a simple string, that contains the data set you need delimited in there somehow. Something like this, where the pipe character delimits the various elements. And within each element the colon character delimits each key name and assigned value.
Value: "Key1:Value1|Key2:Value2|Key3:Value3"
Your third-party code could then parse that delimited string to break out what you are looking for. Make sense?
After trying many ways I skipped the double quotes inside a json string value and passed it as json_sting itself.