Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
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?
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
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.
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 .
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
Thanks Liam. I will be waiting your feedback.
Is there any update on this issue?