So, yesterday we experienced a pretty severe downage as a result of the behavior of the JSON metafield type, and it took me a day of repetition at all levels of our store-import workflow and the additional of seven new surgical Shopify API tools to eventually notice some peculiarities in how the metafield data was being managed, which eventually led to a solution.
About ten days ago, we bit the bullet and bumped our API to 2022-04 (latest). We had to switch from passing “value_type” to “type” in our metafield-creation requests. Looking at the documentation, there used to be a “json_string” type, but it wasn’t listed among the valid types in the documentation or within that variant metafield’s “definition” in the store settings. I did a quick Google search, but only found some release-notes mentions from back in 2018/2019 when that type must’ve been first become available. I also no longer saw a simple “string” type (I now see that a comparable one might be “single_line_text_field”), but I figured the “json” type would be sufficient, anyway. Done.
Today, we suddenly noticed a lot of broken products. Our product pages are very dependent on metafields. Our import process hasn’t changed for a couple of weeks (ever since I made that metafield change), and our import process was correctly creating, updating, and delete variants, creating and updating metafields, and setting inventory. Yet, our pages seemed to not be able to see any metafield data even though I could see it myself (via the “metafields” section under the variant in the Admin).
I could empty a metafield (which induces a metafield removal), set it back to the same value by hand, and our product page would suddenly work. I could make the same change via the API through our tool (remove it by hand, recreate it with the tool), and it’d be broken again. Since I had a formal variant metafield “definition” for this metafield configured in the store setting, the API would only let me declare type in the request as “json” (not sure what the purpose of needing to provide a type in the request, at all, is). The product page was still broken.
I ended-up killing the definition from that metafield in the settings, and then using the “Custom Fields” app to interactive with the metafield values, instead. At one point, after I set it by hand, I exported it via API using a tool and looked at it, and it magically had the totally undocumented “json_string” type (even though the Custom Fields app was still reporting the type of the field as “json”, even if the API now allowed the request to declare any type for a new metafield). Once I started using the “json_string” type in the API-based creation, suddenly my product pages worked again.
So, there are multiple problems here:
-
There is one official JSON type but apparently more than one supported by the underlying architecture
-
Using the only Shopify-hosted metafield-editing mechanism did not work for us (there may be problems in our config or usage, but it’s neither clearly reported or documented).
-
Even though the metafield was reported as having the type “json” in the UI, the value that I manually pasted into Custom Fields got recorded as the “json_string” type. This is insanity and yet the only thing that both worked and exposed the problem.
-
None of the above caused any errors (validation or otherwise) with the API, yet Shopify appeared to have a problem serving this metafield data to the store UI.
These are all pretty serious, and it took about ten days for the problems in production to accumulate to the point that we noticed them.
I would ask that, if nothing else, Shopify updates their metafield documentation to describe, at least, the one missing “json_string” type and how it’s different from “json”, and, possibly, why one is available in the UI and not the other. This was pretty frustrating.
Thank you.