Trying to test the PUT Api in postman , this put api is used update a product, issue in metafield

vipul-lily
Visitor
2 0 0

Trying to test the  Put Api in postman , this put api is used update a product, here's the curl of it as per the document, 
curl -d '{"product":{"id":632910392,"metafields":[{"key":"new","value":"newvalue","type":"single_line_text_field","namespace":"global"}]}}' \
-X PUT "https://your-development-store.myshopify.com/admin/api/2023-10/products/632910392.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"

Now instead of type : "single_line_text_field", i want to use type : " list.single_line_text_field" and here's how the body of put api is , but i get the error stating 

"errors": {
"value": "expected Array to be a string"
}

But as per the document for the type :list.single_line_text_field,  the value should be framed like below, and i have done the same, can you help here! 

[ 
"VIP shipping method",
"Standard shipping method"
]


The URL is
https://e83a4c-2.myshopify.com/admin/api/2021-07/products/8436655128805.json

BODY is :

 
{
 "product": {
 "id": 8436655128805,
 "metafields": [
 {
 "key": "lily-1",
"type": "list.single_line_text_field",
"value": ["VIP shipping method", "Standard shipping method"],
"namespace": "lily"
}
]
}
}

 

Reply 1 (1)

SomeUsernameHe
Shopify Partner
440 48 81

it seems that you are encountering a common issue with the Shopify API when using a list.single_line_text_field metafield type. In your case, the error message "expected Array to be a string" indicates a mismatch between the expected data format for the metafield type and the format of the value you are providing.

In Shopify, different metafield types have specific data format requirements. For the single_line_text_field type, the value is expected to be a plain string with no line breaks, and this type can be used in a list​​. However, when you switch to list.single_line_text_field, it seems that the API might still be expecting a string representation of the list, not an actual JSON array.

A possible solution could involve formatting your list as a string that represents the array. This means you might need to convert your array into a string format that looks like an array but is actually a string.

Here's a general idea:

{
  "product": {
    "id": 8436655128805,
    "metafields": [
      {
        "key": "lily-1",
        "type": "list.single_line_text_field",
        "value": "[\"VIP shipping method\", \"Standard shipping method\"]",
        "namespace": "lily"
      }
    ]
  }
}

 

Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee