Turn tags into Metafields (automated)

Hey there,

i am building a shopify store for a customer with a large product catalog (27.000+ products).

the customer tagged the products with all kind of tags but we are exceeding the filter options in search & discovery so i want to turn some of the tags into metafields.

It would be great to keep the tags in the product but i want to turn some of the tags into metafields.

For example a lot of products contain different ‘‘diameters’’ so a product may say ‘‘ 4’’ diameter ‘‘ and another one ‘‘ 2’’ diameter’ ‘‘.

My idea is to create an automation that checks products for tags that contain ‘diameter’ and puts them into a metafield that is named ‘diameter’ so i have all diameter variants in that metafield while still keeping the tags untouched.

Is that possible with FLOW app by shopify? Do u guys have any ideas on how to solve this ?

Hi Torbz,

I’ve reviewed your requirements, and yes — we can definitely handle this.

Here’s how we can achieve it using the Shopify API:

  • We will create a connector that fetches product data.

  • The connector will process that data and generate the required metafield values.

  • Using the Shopify API, we will then update the product with those metafield values.

If you’re interested, we can discuss the details further on a call.

Thanks,
Sandip Harkhani
Softpulse Infotech Pvt. Ltd

+91 90992 72837

harakhani@gmail.com

This is an interesting challenge! Normally I would approach this by creating a custom script that uses the Admin API to update the metafields, but given Shopify has been making improvements to Flow as of late I gave it a shot as you wanted to know how to do it in Flow and found out it was possible.

The workflow I created is only working with the Diameter metafield but can be augmented to work with other ones as well.

(Check the image at the bottom of my response for seeing how the final flow looks like)

We are using “Product created” as a trigger because there isn’t a “Manual trigger” option yet added to the Flow app, but we’ll be running this manually anyways as you’ll see later.

The most complex part here happens inside that Run code action

The input of that action should be

query{
  product {
    tags
  }
}

The output should be

"The output of Run Code"
type Output {
  diameter: Int
}

And the code should be

export default function main(input) {
  const tags =  input.product.tags;
  let result = {
    
  }
  for(const tag of tags){
    if(tag.startsWith("diameter-")) {
      result.diameter = tag.split("diameter-")[1];
    }
  }
  
  return result;
}

Explanation: there we are querying the product tags and running some code to loop through each one and check if there’s one that starts with diameter-, if there is we are removing that first part (so for example in diameter-2 we remove diameter- and just keep the 2) and return that in the result of this action.

Then add a condition to check if the Run code action returned a diameter. If it did then use the “Update product metafield” action to update the diameter metafield

After giving that workflow a name and saving you can now go to Products in the admin, select all your products, click on the 3 dots and select “Run Flow Automation” (see second part of attached image at the end of this post if you can’t find the “Run flow automation” button)

From there select the one you just created and click “Run workflow”

To support other product tags the Run code action would need to be updated but the idea is roughly the same as what’s already there.

Whoaa, great! Thanks a lot man!

You made my day :slight_smile: