This query will successfully update the product metafield when the metafield is blank.
If I run the query again with another value, to update the metafield again, the metafield will remain with the first value.
I had been initially using the metafield ID, although I ran into an issue where I’m unable to get the metafield ID if the metafield has no value.
The case at hand is that on installation of the app, it needs to update a product metafield with particular values relating to the product.
To do this, it makes a query for all products which will return the product ID and the metafield ID. I found that the metafield ID will return as null if the metafield has no value. This is why I started trying to update the metafield using the namespace and key.
This is the initial query which returns a null metafield ID if the value is blank
Am I going about this the wrong way? The end goal is, upon install of the app, a product ID and metafield ID for each product is stored, and then the metafield (which is empty at this point) is populated with values.
edit: To get around it, in a function that builds the query parameters and string, I’m checking for a metafield ID. If it does not exist, I pass in the namespace and key which works if the metafield is empty. It works but not sure if this is the optimal way of goig about this.