Hello,
I need to add some extra info about a customer. So my plan is to use the metafields of a customer object to store these extra values. I’m able to add new metafields, but when I try to update existing ones, I get an error message: “Key must be unique within this namespace on this resource”.
To update the metafields, I use this GraphQL admin mutation: https://shopify.dev/api/admin-graphql/2021-10/mutations/customerUpdate
This is the request body:
mutation {
customerUpdate(input: {
id: "gid://shopify/Customer/xxx",
metafields: [
{key: "foo", value: "bar", type: "single_line_text_field", namespace: "test"},
{key: "foo2", value: "bar2", type: "single_line_text_field", namespace: "test"}
]
}) {
userErrors {
field
message
}
customer {
metafields(first: 2, namespace:"test") {
edges {
node {
key
value
}
}
}
}
}
}
And here is the result:
{
"data": {
"customerUpdate": {
"userErrors": [
{
"field": [
"metafields",
"7",
"key"
],
"message": "Key must be unique within this namespace on this resource"
},
{
"field": [
"metafields",
"8",
"key"
],
"message": "Key must be unique within this namespace on this resource"
}
],
"customer": {
"metafields": {
"edges": [
{
"node": {
"key": "foo",
"value": "bar"
}
},
{
"node": {
"key": "foo2",
"value": "bar2"
}
}
]
}
}
}
}
}
Is there a way to update a customer’s metafields?