Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Admin API - Metafields error: value must be a single line text string

Solved

Admin API - Metafields error: value must be a single line text string

rohit_martires
Shopify Partner
49 3 7

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 ?

Accepted Solution (1)

rohit_martires
Shopify Partner
49 3 7

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

View solution in original post

Reply 1 (1)

rohit_martires
Shopify Partner
49 3 7

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