value_type and type expected behavior and difference for metafields endpoints in Rest API

Srilekha_T
Tourist
8 0 1

As per the recent changelogs (https://shopify.dev/changelog/online-store-2-0-new-metafields-type-system-and-dynamic-sources), Shopify deprecated the "value_type" field and replaced it with the "type" field. 

Ref: https://shopify.dev/api/admin-rest/2021-10/resources/metafield#resource_object 

Questions:

  1. When we create a metafield with "value_type" as "string" it is populating "type" also with "string" value. As per the list supported fields for "type"(https://shopify.dev/apps/metafields/definitions/types), there is no "string" type and it is rather "single_line_text_field", "multi_line_text_field" etc. Also, is it valid that "type" is also accepting values like string, integer while creating metafields? Is there any reason why the type field is accepting values other than the list of values supported?
  2. Once "value_type" is completely retired, is there any migration carried from the Shopify side to change the "type" field values to any of the list of supported fields here --> https://shopify.dev/apps/metafields/definitions/types or will they still be "integer", "string" etc., 

 

Reply 1 (1)
swalkinshaw
Shopify Staff
Shopify Staff
20 4 9

Good questions!

For compatibility purposes, the new "type" attribute does accept deprecated value types as well. This was done to make the API migration less of a breaking change. Otherwise, when API clients moved from the "value_type" field to "type", they would have also had to change their types would easily could have broken other integrations (such as Liquid in themes). This way, it's fairly easy to update the field name while keeping the rest the same.

However, since metafield definitions are brand new, they only support the new type system. It's up to our merchants and partners to adopt them at their own pace but we do encourage it because of all the benefits they bring.

Note: while we might refer to these existing value types as "deprecated", they aren't going away anytime soon. We can't just change the underlying type of a metafield since it would be a breaking change. So to answer your last question, when the value_type fields are completely removed from our APIs, the "type" value will still remain the same.

I think our docs could probably be improved to explain this situation better, so we'll review them.