Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
How i can store a json object inside the value of metafield of type json_string by graphql its showing error.
when i tried this way:
"metafields": [
{
"namespace": "test2",
"key": "testkey2",
"value": "{'key1': 'value1','key2':'value2'}",
"valueType": "JSON_STRING"
}
]
"value_type": "json_string",
Please let me know how to solve this .how i can pass json i tried with \ this but want to store clean object.
Would be helpful if you showed off more than than that snippet. Try starting off with the exact error, and also more of the code you use to setup and execute the GraphQL mutation.
Mutation :-
mutation productUpdate($input: ProductInput!) {
productUpdate(input: $input) {
product {
id
title
metafields(first: 10) {
edges {
node {
id
value
valueType
}
}
}
}
userErrors {
field
message
}
}
}
Query Variable:-
{ "input": {
"id": "gid://shopify/Product/6688456376473",
"metafields": [
{
"namespace": "test2",
"key": "testkey2",
"value": "{'key1': 'value1','key2':'value2'}",
"valueType": "JSON_STRING"
}
]
}}
So what is your error?
Error:-
"userErrors": [
{
"field": [
"metafields",
"0",
"value"
],
"message": "Value for metafield test2:testkey2 is invalid JSON: 809: unexpected token at '{'key1': 'value1','key2':'value2'}'"
}
]
Probably your use of those single quotes. Try using the usual quotes. Always works for me.
Not working After adding double quotes
Working only by adding / but i don't want to do like this .
Can you share your code snippet that worked for you.
Anyone have any solution of this i want to store data in metafield in the form of the object how to do that.Please help !.
Make sure you're saving JSON as your value. That is all. It works. I have made tens of thousands of JSON_STRING value type Metafields lately in just one App and they work fine. It seems your problem continues to be how you format your JSON.
Please can you show me any example of json format i can enter here.
It worked ,Is is just not working in the shopify-graphiql-app .