Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.

Can't force Metafield Definition creation

CharlyTalavera
Shopify Partner
31 1 9

Hi! I'm trying to create a metafield definition on PRODUCT owner type using GraphQL API, but there are existing metafield values for the namespace/key I'm using.

 

When I use metafieldDefinitionCreate, I end up with the error "Namespace and key is already in use for a set of your metafields".

 

I saw in the Shopify Admin page that is possible to "add a definition" for "metafields without definition".
The Shopify Admin page is using a `forceCreate` field that was available previously in the GraphQL, but in the latests versions that field has been removed. 

How can I create a Metafield Definition from a Metafield like Shopify does using the GraphQL API? Does somebody know if Shopify pretends to add again the field `forceCreate` at some point?

Replies 8 (8)

Liam
Shopify Staff
2669 288 730

Hi CharlyTalavera,

 

The GraphQL API requires unique namespace/key pairs for each metafield definition, which is why you're running into this issue. Could you update the existing metafields to use a different namespace/key pair before creating the new metafield definition? Otherwise if the existing metafields are necessary and can't be updated or deleted, you could use a different namespace/key pair for your new metafield definition? 

 

Is the a specific use-case you have where you'd need to overwrite the existing metafield values for the namespace/key by creating a new metafield definition?

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

CharlyTalavera
Shopify Partner
31 1 9

Hi Liam! Thanks for you time!

Could you update the existing metafields to use a different namespace/key pair before creating the new metafield definition?

 

Sorry if I don't understood you properly, but I guess that's not ideal. Since we have hundreds of merchant that are using the application and set a value to those metafields already. So using another metafield means that we would need to run a migration to move existing values to the new metafields for all existing products for all stores. I'm looking for an alternative less risky for our production environments, since create a Metafield definition from a Metafield is something possible in Shopify Admin. And Shopify Admin using this same mutation as we do, but Shopify is passing a `forceCreate` field that is not available on our end.

I attached an screencast pointing how Shopify does it, and which field we don't have available in the GraphQL mutation.

Is the a specific use-case you have where you'd need to overwrite the existing metafield values for the namespace/key by creating a new metafield definition?

Yes, because the Metafields are already on production since a long time ago, and now we want to display them in the Shopify UI, without breaking the user set up. Values for those metafields has been setup by users, and the migration process would be risky and unnecessary if there is any other alternative.

Thanks for your time Liam! If i need to explain my self better or didn't get you correctly, let me know.

CharlyTalavera
Shopify Partner
31 1 9

Hi @Liam , did you have time to recheck my answer?

Thanks for you time!

nnthuanspf
Shopify Partner
4 0 2

Hi @Liam , @CharlyTalavera 

Yes, I have the same problem, I also checked and in Shopify Admin use `forceCreate`, but in Graphql this parameter is not usable, hope to add as soon as possible, best regards .

 

BCSE
Shopify Partner
2 0 0

Hi @Liam , @CharlyTalavera 

Yes, we also have the same problem here.

Liam
Shopify Staff
2669 288 730

Hi again Charly,

 

It's possible the `forceCreate` field is not publicly available in order to avoid overwriting issues happening with metafields, but I'll connect with the custom data team internally to see what would be the best approach here. 

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

CharlyTalavera
Shopify Partner
31 1 9

Thanks Liam. I will be waiting your feedback.

GerwinB
Shopify Partner
78 2 14

Is there any update on this issue?