Possible to create metafield with a preset list of values via an app?

Solved

Possible to create metafield with a preset list of values via an app?

lesterdefreitas
Shopify Partner
25 0 10

Context:

 

We have created a custom app for a Plus merchant that needs some specific additional address fields captured at checkout, and they need these values captured into order metafields. The fields are dropdowns with predefined options for address validation purposes in regards to their fulfillment platform integration.

 

All is good and well with that and we have achieved their requirement in this regard.

 

However, they also have sales reps that create draft orders from the back end of Shopify for customers, and they need those custom fields to also be available in the back end when those reps create the orders. This is already the case, in a sense, in that once the Draft order is created and becomes an "Order", the custom fields are there by virtue of the fact that they exist as metafields in the admin.

 

However the issue is that the metafields do not have the predefined options as a dropdown in the back end—at least not unless we manually add preset values to the metafield definitions of course, which is however very impractical as there are so many options and the app is going to be used on something like 25 plus stores.

 

The question:

 

So that brings us to the original query: Is it possible, via the API, that when we create these order metafields, we can also create the preset options for them so that they behave us dropdowns in the admin like they do when you manually add preset options to text metafields?

Lester de Freitas
The Web Elite | Shopify Experts
Accepted Solution (1)

Liam
Shopify Staff
2862 313 816

This is an accepted solution.

Hi Lester,

 

Currently, Shopify's API does not support creating predefined options for metafields. The metafields API allows you to set key-value pairs, but it doesn't support defining a set of valid options for those keys. The functionality to add preset options to metafields in the Shopify admin is not available through the API yet.

 

As a workaround, you could possibly maintain a separate configuration file or external database that holds the valid options for each metafield, and have your app refer to that. But this wouldn't integrate with the Shopify admin and wouldn't provide the dropdown functionality you're looking for in the admin interface.

 

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)

Liam
Shopify Staff
2862 313 816

This is an accepted solution.

Hi Lester,

 

Currently, Shopify's API does not support creating predefined options for metafields. The metafields API allows you to set key-value pairs, but it doesn't support defining a set of valid options for those keys. The functionality to add preset options to metafields in the Shopify admin is not available through the API yet.

 

As a workaround, you could possibly maintain a separate configuration file or external database that holds the valid options for each metafield, and have your app refer to that. But this wouldn't integrate with the Shopify admin and wouldn't provide the dropdown functionality you're looking for in the admin interface.

 

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

lesterdefreitas
Shopify Partner
25 0 10

Hi Liam,

 

Thanks for the clear answer, that helps. I really think it would be good if the API could support adding preset values to metafields. But in the meantime we are going to try another workaround. Thanks again for the response.

Lester de Freitas
The Web Elite | Shopify Experts