How to set metafield with multiple values using Python

Hello,

I am trying to set a metafield on some products, that may have multiple options, like the image attached.

My code is the following:
value = [‘test’,‘test2’]

metafiled = shopify.Metafield(
{
‘key’: ‘product_test’,
‘value’: value,
‘type’: ‘list.single_line_text_field’,
‘namespace’: ‘custom’,
}
)
product.add_metafield(metafiled)
product.save()

But this is not working. Documentation has no examples on such case. Any ideas?

Hi @B3th3sd4 ,

It appears that you’re trying to pass a Python array as the metafield value, which is not the best idea since the API would expect all attributes to be strings. Have you tried converting your array to a proper JSON array literal?

1 Like

As MetafieldsGuru already helpfully explained, the value should always be passed as a String. In Python, you can use the json.dumps method to convert your Array value to a JSON String.

1 Like

Thank you very much. I should expect that since all the API is JSON oriented.

Did you get a solution? If so please add the python code.