I create and update products via graphQL productSet calls:
https://shopify.dev/docs/api/admin-graphql/latest/mutations/productset
I found a few problems with creating/udating/deleting metafields with this mutation:
-
On creating the Product I supply a list of MetafieldInputs. For each MetafieldInput I supply the fields: namespace, type, key, value.
-
All metafields are created, I can see them in https://admin.shopify.com, including metafields with definitions and unstructured metafields .
-
But in the returned productSet product object, only metafields that have definitions are returned. Unstructured metafields are not returned.
-
When I read the product using the product query, the same, only metafields that have definitions are returned. Unstructured metafields are not returned.
-
Further I am talking about metafields with definitions.
-
I can change a metafield value of an existing metafield changing the value for the corresponding key in the MetafieldInputs and using productSet. API returns the list with the changed value. It is fine.
-
I can remove a metafield deleting it from the MetafieldInputs list and using productSet. The metafield is removed, API returns the list with this metafield absent. In https://admin.shopify.com this metafield field is still present but its value is empty. I think it is probably fine.
-
Then I try to restore this metafield. I add it again to the MetafieldInputs list and use productSet. The matafield is actually added again, I can see it in https://admin.shopify.com with the new value. But it is not returned in API productSet product object. And when I read the product using the product query, the same, this newly added metafield is not returned.
So the problems:
-
Unstructured metafields are never returned by API (nor on productSet return, nor on product query).
-
A deleted metafield with a definition, and then restored (added again) are never returned by API (nor on productSet return, nor on product query).