I’m implementing a Discount update function using discountCodeAppUpdate, and meet this problem. When I call to update a discount, I received this message in the response body “Namespace and key cannot be changed for an existing record. Try creating a new one.”. Is there anyone who meets this problem and how to solve it?
Here is my query:
query = <<~QUERY
mutation discountCodeAppUpdate($codeAppDiscount: DiscountCodeAppInput!, $id: ID!) {
discountCodeAppUpdate(codeAppDiscount: $codeAppDiscount, id: $id) {
codeAppDiscount {
discountId
title
endsAt
}
userErrors {
field
message
}
}
}
QUERY
Here are my params:
{
:id=>"gid://shopify/DiscountCodeNode/xxxxxxxxxxxxx",
:codeAppDiscount=>{
:code=>"123",
:title=>"Test",
:appliesOncePerCustomer=> false,
:metafields=> {
"namespace"=>"$app:discount-code-advanced", "key"=>"function-configuration", "type"=>"json", "value"=>"{\"allOrAnyCriteria\":\"all\",\"selectCustomersBy\":{\"name\":\"none\",\"inputs\":[]},\"selectCartBy\":{\"name\":\"none\",\"inputs\":[]},\"selectLineItemBy\":{\"name\":\"none\",\"inputs\":[]},\"discount\":\"{{code => \\\"123\\\", type => \\\"fixed\\\", amount => \\\"123\\\"}}\"}", "id"=>"gid://shopify/Metafield/xxxxxxxxxxxx"
}
}
}
Here is the response body:
{"data"=>{"discountCodeAppUpdate"=>{"codeAppDiscount"=>nil, "userErrors"=>[{"field"=>["codeAppDiscount", "metafields", "0", "id"], "message"=>"Namespace and key cannot be changed for existing record. Try creating
a new one."}]}}, "extensions"=>{"cost"=>{"requestedQueryCost"=>10, "actualQueryCost"=>10, "throttleStatus"=>{"maximumAvailable"=>1000.0, "currentlyAvailable"=>990, "restoreRate"=>50.0}}}}