I am trying to use the metafieldsSet mutation (https://shopify.dev/api/admin-graphql/2022-04/mutations/metafieldsSet ) for a metafield of type list.single_line_text_field
When I try
value: ['test']
I get the error
Could not coerce value ["test"] to String
And when I try
value: 'test'
I get the error
Value must be an array.
I don’t know what else to try or what data type should be used as a value… any suggestion is welcome!
Thanks
KathB
June 13, 2022, 1:41pm
2
Hi there,
the value needs to be entered as a json string, like so…
hey i tried this by converting my array to json via JSON.stringfy(arr) but i’m getting this error
“value”: [> ┃ “must be a single line text string.”> ┃ ]
metafields = await client.post({
path: 'metafields',
data: {
metafield: {
order_id: `gid://shopify/Order/${order_id}`,
namespace: "web_3",
key: "gated_wallet_line_items",
value: arr,
type: "list.single_line_text_field",
}
},
type: DataType.JSON
});
when u check typeof arr its showing string still getting this error tho not sure what i’m doing wrong ?
Just a thought: you are passing type: “list.single_line_text_field” in the API, but does this metafield already have a definition (in the store settings)? Could it be that this definition is not “list.single_line_text_field”?
no i dont have any custom metafields set for the store, btw did JSON.stringify() work for you ?
Yes, it worked for me… but I am using the GraphQL metafieldsSet mutation, it looks like you are using the REST API. Maybe they behave differently.
Oh and for the REST API, I think it’s value_type, not type. That could be the issue.
i tried both getting the same error on both rest/graphql
value_type is for the old api version i’m currently using the april_22 version.
I have also had problems with this mutation when trying to create or update a metafield with a definition.
The mutation itself seems to require a string value, but passing a string value to try and set, for example, an integer metafield, throws an error because the value can’t be coerced to an integer…
if you still have this issue i posted my fix here: https://community.shopify.com/topic/1636693