App reviews, troubleshooting, and recommendations
Hi all!
I'v a problem when I try to create a metafield of type json:
const value = {"test":"test"} const response = await admin.graphql( `#graphql mutation CreateAppDataMetafield($metafieldsSetInput:[MetafieldsSetInput!]!) { metafieldsSet(metafields: $metafieldsSetInput) { metafields { id namespace key } userErrors { field message } } } `, { variables: { metafieldsSetInput: { namespace: "block_metafields", key: "test", type: "rich_text_field", value: JSON.stringify(value), ownerId: data.get('id') } } } ) const metafield = await response.json() console.log(metafield.data.metafieldsSet.userErrors)
The console:
[
20:57:06 │ remix │ {
20:57:06 │ remix │ field: [ 'metafields', '0', 'value' ],
20:57:06 │ remix │ message: 'Value is not the correct format:
failed schema "test" is not a permitted key.'
20:57:06 │ remix │ }
20:57:06 │ remix │ ]
I tried with other keys, it doesn't work... where is the error?
Thanks!
Solved! Go to the solution
This is an accepted solution.
If you are trying to create "a metafield of type json" then your
type: "rich_text_field",
should be
type: "json",
But if it doesn't fix the error, the error message failed schema "test" is not a permitted key suggests that the key "test" may not be allowed under the schema of the metafield or that the API call doesn't have the correct permissions to set a metafield with this key. Ensure that the key is valid and permitted under your current API permissions and the metafield definitions in Shopify.
https://shopify.dev/docs/apps/custom-data/metafields/types
This is an accepted solution.
If you are trying to create "a metafield of type json" then your
type: "rich_text_field",
should be
type: "json",
But if it doesn't fix the error, the error message failed schema "test" is not a permitted key suggests that the key "test" may not be allowed under the schema of the metafield or that the API call doesn't have the correct permissions to set a metafield with this key. Ensure that the key is valid and permitted under your current API permissions and the metafield definitions in Shopify.
https://shopify.dev/docs/apps/custom-data/metafields/types
Thank you so much!
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024