Automatically Linking Variant Option with Product Category Metafield via API

Hi all!

We have developed a custom connector that reads an Excel file and uses the API to create products along with all their relevant fields. Everything works well so far.

As you know, Shopify products can have a base category. I’m successfully setting this (e.g., “Shoes”) using PHP and GraphQL. So each product has its core data correctly filled in.

For the variations, I’m using a custom Metafield called “Shoe Size,” which populates correctly, along with the SKUs for each variant.

Here’s the issue I’m trying to solve:

When a user manually creates a product in the admin and assigns a category like “Shoes”, Shopify then displays the Product Category Metafields related to that category, and the user can manually fill them in — and that works fine.

However, in our case, we are bulk uploading products via our connector, and all relevant data already exists. What we need is a way to programmatically populate or link the appropriate Product Category Metafields (e.g., connect our “Shoe Size” variant option to the “Shoe Size” Product Category Metafield) — without any manual input in the admin interface.

Can this kind of automatic connection or update be achieved through the API, or is it something that can only be done manually?

Looking forward to your advice.

Hi @George_Chouliaras

There is no direct API mechanism to “link” a variant option (like your “Shoe Size” option) to a category metafield so that Shopify automatically syncs them. This means you must manually set the metafield value to match the variant option value if you want them to be in sync. So, during your bulk upload, after creating the variants, you should also set the corresponding category metafield values using the metafieldsSet mutation.

Thank you for your answer!