Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Namespace and key cannot be changed for existing record. Try creating a new one.

Solved

Namespace and key cannot be changed for existing record. Try creating a new one.

JohnDoe3
Shopify Partner
8 0 1

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}}}}

 

Accepted Solution (1)

Liam
Community Manager
3108 344 910

This is an accepted solution.

Hi JohnDoe3,

 

What might be happening here is that the API may be thinking that you're trying to update the namespace and key of a metafield (which is not possible), rather than the value of the metafield. If you exclude the namespace and key fields from the metafields input are you still seeing an error?

 

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 3 (3)

Liam
Community Manager
3108 344 910

This is an accepted solution.

Hi JohnDoe3,

 

What might be happening here is that the API may be thinking that you're trying to update the namespace and key of a metafield (which is not possible), rather than the value of the metafield. If you exclude the namespace and key fields from the metafields input are you still seeing an error?

 

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

JohnDoe3
Shopify Partner
8 0 1

I have tried to exclude the namespace and key fields. The features are running well now. Thank you very much, Liam!

Liam
Community Manager
3108 344 910

Great to hear!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog