Update metaobject with Product List Type

I’m trying to add a product reference to a field of product type using the admin API mutation

I’m getting the following error

Mutation had errors: “Variable $metaobject of type MetaobjectUpdateInput! was provided invalid value for fields.0.value (Could not coerce value [“gid://shopify/Product/8649501638818”] to String)”

I’ve tried so many different version but nothing works

From the error message, should value, just be the product id. Not a list with the product id in? :thinking:

Not sure those screenshots match. In the top, you are missing quotes around that variable.

But yeah, it’s hard to answer this without knowing the schema of your metaobject

Its a product_reference field expecting a list of product I think the error was based on {{ product.id | json }}

I tired using just the ID itself and got the same error message

Got it working, the array also needed to be wrapped in quotes

Is there a more elegant way of adding to an existing list? Currently using

    "fields": [
      {
        "key": "products",
        "value": "[{{ getMetaobjectEntry.products | map: 'id' | join: '\", \"' | append: '\",' | prepend: '\"' }}{{product.id | json | replace: '"', '\"'}}]"
      }
    ]
2 Likes

You can use Run code before this action and they can you can use JavaScript to handle the list