Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Hi,
I'm trying to modify the value of a metafield attached to a customer.
i'm using the metafieldsSet like said in this post .
But i keep getting the error "Field 'metafieldsSet' doesn't exist on type 'Mutation'".
Someone said that it was an API version issue, that metafields doesn't existed prior to 2021 version.
But i'm using the 2024 version, i also tried the 2021-10 but keep getting the error...
Here is my full request :
await $fetch(`https://${process.env.SHOP_NAME}.myshopify.com/api/2021-10/graphql.json`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Storefront-Access-Token': process.env.SHOPIFY_KEY
},
body: JSON.stringify({
query: `
mutation {
metafieldsSet(metafields: [
{
namespace: "custom",
ownerId: "${customerId}",
key: "company",
value: "${body.company}"
},
]) {
metafields {
key
value
}
userErrors {
field
message
}
}
}`
})
});
CustomerId and my API key are correct, and body.company is a string. The metafield exists because i can manually set it's value on my shopify admin page.
Thanks for your help,
Almay
Solved! Go to the solution
This is an accepted solution.
Found a solution.