Update Google: Color Variant Metafield based on Product Options containing a Color Value

Topic summary

A user is building a Shopify Flow to automatically update a Google Shopping color metafield based on product variant options.

Current Progress:

  • Successfully triggers on inventory quantity changes
  • Successfully identifies when “color” exists in position 1 of product options
  • Plans to extend logic to positions 2 and 3

Main Issue:
The action step is returning all option values (e.g., “Orange”, “28mm”) instead of just the color value, causing an error: “Value must be a single line text string.” The user needs code to extract only the option value where options_item.name = color.

Partial Solution Provided:
A respondent clarified the metafield namespace/key structure should be split as:

  • Namespace: “mm-google-shopping”
  • Key: “color”

Outstanding Question:
The user still needs help with the specific code/logic to filter and return only the color option value from the correct position, rather than concatenating all option values. A similar approach will be applied to a Google Size metafield afterward.

Summarized with AI on November 1. AI used: claude-sonnet-4-5-20250929.

Hello,

I am trying to write a Flow which triggers on a Product variant inventory quantity being changed, the trigger works. The check if I am using is if options_item.position = 1 and options_item.name = color, that also works and tells me that color is is in the first position. Once I get it to work I would create two more check ifs for position 2 and 3, maybe there is a way to do all in one but I am a novice.

My issue is the Action step, specifically the code I need to grab the option name from position 1, or the position where options_item.name = color.

The above returns the following error for the product I am testing. Exception: Got error updating metafield: “Value must be a single line text string.” For value: “\n Orange\n\n 28mm\n\n\n”, Type: single_line_text_field

This leads me to believe I either need an if statement to only return the option value in position 1 or there some sort of other reference I am missing. Any help would be very appreciated! I intend to the same with the Google: Size Metafield.

Steve

Hi Steve :waving_hand: For the metafield “mm-google-shopping.color”, the namespace is the string before the period and the key is the string after. In your step configuration, the namespace should be “mm-google-shopping” and the key should be “color”.

Thank you, I will make that change. But I don’t think that fully solves my problem because I want it to only return the value of the Option with name matching color, in this case that is position 1. Can you help with the code needed?