No worries.
I did some further testing to see how admin UI handles metafield updates and updating the metafield values there worked as expected without any errors.
That led me back to our documentation for a closer look at what’s expected with metafields. I found that the metafields
parameter in discountAutomaticAppUpdate is specifically designed for adding additional metafields, not updating existing ones.
“Additional metafields to associate to the discount.”
The solution here is when updating existing metafields via the GraphQL API, use the metafieldsSet
mutation instead. This mutation handles both creating and updating metafields without the constraint issues:
mutation {
metafieldsSet(
metafields: [
{
ownerId: "YOUR_DISCOUNT_ID"
namespace: "$app:discount-function-test"
key: "function-configuration"
type: "json"
value: "{\"cartLinePercentage\": 25, \"orderPercentage\": 15, \"deliveryPercentage\": 100, \"collectionIds\": []}"
}
]
) {
metafields {
id
namespace
key
value
}
userErrors {
field
message
}
}
}