How to update product options when the product is using metafield?

Hi there!

I am having another incredibly messy experience with the variant update so I think there must be something that I don’t understand. I feel like I have already read a lot about this but I cannot find the solution I am looking for.

Let’s say that I create a product with 2 variants, Color Blue and Red (those are metafields). My app will receive the webhook and create the 2 variants, Blue and Red. I also store the options in my app.
Now, the user goes into my app and want to change the Red to Green. He can simply open the variant form, and change Red to Green in the select list. My app will then update the variant in Shopify to reflect that change …

Until now, I have always been able to simply set the name and optionName and send this to Shopify (in a REST variant update endpoint).
Now, with metafields, I have no idea how to do this. Now I get the error “Cannot set name for an option value linked to a metafield”. How am I supposed to do this? Isn’t supposed to be simple?

Thanks for your help,
Ed

You can’t just rename the option value when its tied to a metafield.

I think you should update the linked metafield value using productOptionUpdate or productOptionsCreate

Thanks for the reply ! :slight_smile:

This is what I think I understand, but isn’t the experience just awful ? When I update a variant, I need to update a product now ? Should I store the Metafield IDs somewhere in my app (I don’t want that !) ? I couldn’t find any exemple of this. But everything that I think I understand make me realize how hard it is to update a variant.
What I could find, is that Shopify Graphql API just deprecated a variantUpdate mutation where is looks like it was possible. There also wasn’t any issue with REST.

Metafields might be great (even though I highly don’t care about it), but it should me Shopify, not me, who has to deal with it when using the API. If I send Green instead of Red, they should be the one matching it with the right metafield.

I have to admit, I am a bit tired of this new GraphQL API. I am a bit fan of GraphQL, my whole app is built using this, but Shopify decoupled every little operation and makes it very hard to us. Each simple thing we want to do has to be done in so many steps …