A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hey so i'm trying to set metafields on a order, i have tried both the admin rest and graphql api both give the same error saying: error: value must be a single line text string.
problem is the value i'm passing is a JSON strigyfied array i.e.
let metafield_value = JSON.stringify(draft_order.line_items.map(x => x.id));
let metafields = await client.post({
path: 'metafields',
data: {
metafield: {
order_id: `gid://shopify/Order/${order_id}`,
namespace: "web_3",
key: "gated_wallet_line_items",
value: metafield_value,
type: "list.single_line_text_field",
}
},
type: DataType.JSON
});
if i check typeof for metafield_value it shows string so i'm not sure what i'm doing wrong ?
Solved! Go to the solution
This is an accepted solution.
let metafield_value = draft_order.line_items.map((x) => String(x.id));
metafield_value = JSON.stringify(metafield_value);
this works
This is an accepted solution.
let metafield_value = draft_order.line_items.map((x) => String(x.id));
metafield_value = JSON.stringify(metafield_value);
this works