How to programmatically determine app owned Metafields?

How to programmatically determine app owned Metafields?

mitchnick
Shopify Partner
4 0 1

We have an app that takes returned products and uploads them for resale. We do this by creating a duplicate of the original product and adding the "used" version of the new product. Our customers want us to copy all of the possible metafields over as possible, this allows the newly listed returned product to behave the same as the existing product. This is especially important for how Shopify Themes 2.0 is setup. 

Today when trying to create a new product I got the following message:

 

 

"Access to this namespace and key on Metafields for this resource type is not allowed."

 

 


I can see all of the metafield namespaces that we are trying to create: 

 

 

["c_f", "global", "reviews", "spr", "mm-google-shopping", "r4s", "custom", "product_recommendation"]

 

 


But I do not have any indication which of these fields would be preventing us from creating the new product. I can see the following attributes on the metafield data returned from the original product, but none of these give me a sense of if it's a metafield available for me to write on. 

 

 

["id", "namespace", "key", "value", "description", "owner_id", "created_at", "updated_at", "owner_resource", "type", "admin_graphql_api_id"]

 

 

 
Looking for any advice here from the team at Shopify or the community on how to handle.

Replies 3 (3)

richard-penner
Shopify Staff
19 2 6

Hi @mitchnick,

 

Great question. I have a suspicion that metafields in the "product_recommendation" namespace are not meant to be copied from one product to another. In terms of metafields APIs I'm not sure there is a way to determine that programmatically. Try excluding metafields in that namespace in the meantime, and I will report back if I can find a way to determine this programmatically. 

To learn more visit the Shopify Help Center or the Community Blog.

richard-penner
Shopify Staff
19 2 6

Hi again @mitchnick,

 

If you are using REST you will have to manually exclude metafields in the "product_recommendation" namespace. 

 

Instead of REST though I would suggest you look at the productDuplicate GraphQL API to duplicate products. It will duplicate the product and its metafields, and automatically exclude this namespace.

To learn more visit the Shopify Help Center or the Community Blog.

mitchnick
Shopify Partner
4 0 1

Thanks Richard for the quick response! I removed the product_recommendation namespace as you mentioned and the record saves as it used to. We'll look into migrating to GraphQL in the future, the app was originally written before the big push to do more through GraphQL. 

Thanks again for the help 🙂