Error: Metafields.key must be unique

Shopify Staff (Retired)
Shopify Staff (Retired)
960 1 51

Hey Nancy!

We rolled out a fix to this issue a little while ago, but if you're still getting the error, shoot me an email at matthew.buttler@shopify.com and I'll send this up to the team to take a look. If you can, please provide a screenshot of the error happening, too.

 

Talk to you soon!


Matthew Buttler
Guru
Shopify Inc.

 

0 Likes
New Member
1 0 0

Dear Matthew!

Same problem here.

The issue seems related to metadata description. As soon as I add some meta-desc the error appears. If I remove it I can save with no issue.

I'll send you over the printscreen.

Kind Regards

Lele

0 Likes
New Member
7 0 0

I faced the same problem. Refresh the page and the error goes off. 

0 Likes
Tourist
31 0 1

I am having this issue. Please see attachment

 

0 Likes
Shopify Partner
8 0 3

I think there may be a bug in Shopify's API, or at least, some inconsistency.  You can create metafields when you create a new customer via a POST request, but the behavior of editing an existing customer via a PATCH (or PUT) request does not appear to be correct.   You can add metafields by supplying a list of them when you make a PATCH or PUT request and the fields will get added but only if they contain the unique namespace.key.  Proper implementation of the PUT or PATCH methods should change all fields for the metafields property, but instead, the values of the existing fields prevent the update.

 

I think Shopify is trying to make things a bit easier by proxying the metafield resource requests when you manipulate the customer (or product et al) resources.  The only way I have found to deal with this is to skip Shopify's attempts at simplification: find the ids of all the metafields that you're dealing with and make regular DELETE/PATCH requests against the metafield resources.  Unfortunately, this can mean lots of additional requests.


1 Like
Tourist
8 0 5

Hello,

Not sure if this thread is still alive, but I wanted to +1 @Everett_Griffit 's comment.

Firstly, I can confirm that like Everett mentions, the Shopify API does behave this way: when you make a PUT request to an existing Shopify object (such as a customer), you are not able to make changes to the object's existing metafields. In other words, while I can make changes to a customer's phone field for example, I cannot make changes to the customer's birthday (for example, because birthday needs to be stored as a metafield) in the same patch request. However, oddly enough, if I attach a new metafield (so with a new and unique namespace) to the customer object in the same PUT request, the metafield does get created!

What I would like ideally, is the ability to change existing metafields on a Shopify object in a PUT request. The only way to change an existing metafield's value in a PUT request is by the metafield ID which is not developer-friendly. Like Everett commented, this would force multiple requests for changes to a single object model :( 

Here's a real use case in which this limitation has affected my private app. My private app aims to allow customers to modify their "customer profile" - by using a form with input fields such as phone, email, and birthday. However, birthday is a metafield as it is not a built-in customer field in Shopify. Therefore, when the customer submits his profile form (with changes to his phone and birthday for example), the changes cannot be done in a single PUT request! I need to make separate requests for each customer field that is stored in a metafield. Is this intended behavior?

 

Am I correct in this? If this IS how Shopify's API currently is behaving, would it be possible to get this feature?


Thank you,
John

1 Like
New Member
1 0 0

+1 on jasperking comment

It kind of defeats purpose of GraphQL API because I have to make separate requests to get metafields: in my case I have to get them from Product, filter existing ones out of the update and only then send update request, which seems kind of cumbersome for API user.

0 Likes