Issue with Updating mihai_variable_gallery Metafield in list.file_reference Format via the API

I am working on integrating Shopify’s Admin API for our store(store URL: rrtrxj-h1.myshopify.com).

I am attempting to update a custom metafield (mihai_variable_gallery) of type list.file_reference for a specific product variant, but I am encountering errors during the process.

Metafield Details

Metafield Key: mihai_variable_gallery

Metafield URL in Admin: /store/rrtrxj-h1/settings/custom_data/productvariant/metafields/187111211345

Metafield Type: list.file_reference

Product Variant Details

Product Variant URL in Admin: /store/rrtrxj-h1/products/9864017871185/variants/50241067090257

Product ID: 9864017871185

Variant ID: 50241067090257

Issue Description

I am trying to update the mihai_variable_gallery metafield with the following values:

[“gid://shopify/ProductImage/66131787907409”, “gid://shopify/ProductImage/66131788005713”]

Errors Encountered

  1. When passing the array as a JSON-encoded string:

Request:

{

“metafield”: {

“namespace”: “custom”,

“key”: “mihai_variable_gallery”,

“value”: “["gid://shopify/ProductImage/66131787907409"]”,

“type”: “list.file_reference”

}

}

Response Error:

metafields.value: must be a file reference string.

  1. When passing a single file reference string:

Request:

{

“metafield”: {

“namespace”: “custom”,

“key”: “mihai_variable_gallery”,

“value”: “gid://shopify/ProductImage/66131787907409”,

“type”: “list.file_reference”

}

}

Response Error:

metafields.value: must be an array.

  1. When passing the value as an array directly:

Request:

{

“metafield”: {

“namespace”: “custom”,

“key”: “mihai_variable_gallery”,

“value”: [“gid://shopify/ProductImage/66131787907409”],

“type”: “list.file_reference”

}

}

Response Error:

value: expected Array to be a String.

Debugging Steps Taken

  1. Ensured the file references (e.g., gid://shopify/ProductImage/66131787907409) are valid and exist in Shopify.

  2. Used Go’s json.Marshal to encode the array into a JSON string for proper formatting.

  3. Confirmed that the metafield type is correctly set to list.file_reference.

  4. Tested payloads using both Shopify’s Admin API and Postman, but the errors persist.

Request for Assistance

Could you please help me understand the following:

  1. What is the exact format required for the value field when updating a metafield of type list.file_reference? It seems I go in circles. When I use an array I get an error that it must be string and the other way around.

Could you please try like below?


{
  "metafields": [
    {
      "key": "materials",
      "namespace": "my_fields",
      "ownerId": "gid://shopify/ProductVariant/42143107645500",
      "type": "list.file_reference",
      "value": "[\"gid://shopify/MediaImage/30268388933692\"]"
    }
  ]
}

I finally figured it out. The issue was that I was using existing images of the product. I had to upload new images using the File API and now the GID`s are accepted. Very frustrating and useless/cryptic error messages.

1 Like

Could you please explain how you found the solution for this? Specifically how you’re using the File API? I am also trying to use an existing product image as the value for a metafield file_reference definition but nothing I’m doing is working. I’m not even getting any errors, my store is just not registered the file to the metafield