Update custom collection metafields

Hey Everybody,

I’m hving issues updating the metafields of a custom collection only.

When I try to update the collection it runs well, but if I try to add metafields object to the API call I get 422 unprocessible entity.

What I try to call is:

PUT /admin/custom_collection/206042311.json

And I send this info.

{"custom_collection":{"id":206042311,"metafields":[{"key":"size","namespace":"sbtd_collection_filter","value":"size--large, size--medium, size--small","value_type":"string"},{"key":"color","namespace":"sbtd_collection_filter","value":"color--blue, color--green","value_type":"string"},{"key":"style","namespace":"sbtd_collection_filter","value":"style--srafciger, style--testproduct","value_type":"string"}]}}

All according to https://help.shopify.com/api/reference/customcollection

I tried with a single metafield inside to no avail. Any other data I try to update colection with works properly, but metafields no. Any help guys, please, really stuck.

I use PHP & CURL to make my calls. Also, same happens when I try to create a new custom collection via API, works if I don’t put in the metafields.

This will also be the issue with collects I bet, wonder what I’m missing here..

Thanks in advance!

Hey Ivan,

If you’re trying to update an existing collection with a metafield try something more like this:

POST /admin/collections/206042311/metafields.json

{
  "metafield": {
    "namespace": "foo",
    "key": "bar",
    "value": 25,
    "value_type": "integer"
  }
}
1 Like

Thanks JSON! :smiley:

I did try and it worked!

Now, I came accross a weird but true case.

If metafield namespace contains the word collection, it won’t save, instead, 422 error is thrown! This happens when assigning a metafield to a custom collection, not sure about other owners, but feels that avoiding resource name when picking your namespace is a good practice here.