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.

GraphQL Admin API - metafieldSet for type list.single_line_text_field

Solved

GraphQL Admin API - metafieldSet for type list.single_line_text_field

acerill
Shopify Partner
12 1 9

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

Accepted Solution (1)

KathB
Shopify Staff
7 2 5

This is an accepted solution.

Hi there,

the value needs to be entered as a json string, like so...

Screen Shot 2022-06-13 at 9.40.27 AM.png

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 9 (9)

KathB
Shopify Staff
7 2 5

This is an accepted solution.

Hi there,

the value needs to be entered as a json string, like so...

Screen Shot 2022-06-13 at 9.40.27 AM.png

To learn more visit the Shopify Help Center or the Community Blog.

rohit_martires
Shopify Partner
49 3 7

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 ?

acerill
Shopify Partner
12 1 9

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"?

rohit_martires
Shopify Partner
49 3 7

no i dont have any custom metafields set for the store, btw did JSON.stringify() work for you ?

acerill
Shopify Partner
12 1 9

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.

acerill
Shopify Partner
12 1 9

Oh and for the REST API, I think it's value_type, not type. That could be the issue.

rohit_martires
Shopify Partner
49 3 7

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.

Sam-Deakin
Shopify Partner
2 0 0

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...



rohit_martires
Shopify Partner
49 3 7