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 firstname.lastname@example.org 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!
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.
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?