Admin rest api update list.product_reference

Hi community,

I try to update an metafield of type list.product_reference (changed here the id to something which does not exists on purpose). According to the documentation https://shopify.dev/apps/data-extensions/metafields/types the value must be an array. But it does not work, because of the value. Tried many different ways, but no success.

URL: https://.myshopify.com/admin/api/2023-01/products/1000000000013.json

Method: PUT

{
“product”: {
“id”: 1000000000013,
“metafields”: [{
“key”: “metaname”,
“value”: [“gid://shopify/Product/1000000000013”],
“type”: “list.product_reference”,
“namespace”: “custom”
}]
}
}

Returned is always a Bad Request.

Many thanks for your support

Hi Despi,

When using the Admin API to read and write metafields, the value is always entered and stored as a string, regardless of type.

For list values, this means you should input a stringified array. Using the example shown above, that would be “["gid://shopify/Product/1000000000013"]”.

2 Likes

Hi @JohnBerry

thank’s a lot, much appreciated. Solution works perfectly.

1 Like