"Unable to update multiple metafields in a single PUT request."

2 0 0

Hi, I'm trying to use this API:




PUT /admin/api/2023-04/variants/808950810.json

example body:



    "variant": {
        "id": 808950810,
        "price": 12.79,
        "metafields": [
                "key": "symbol",
                "value": "asdasd",
                "type": "single_line_text_field",
                "namespace": "custom"


And it works as described below:

  • If the metafield isn't set on this variant, it will work fine; it will set the value and return a 200 response.

  • If the metafield already contains a value, it will return a 422 error with "could not be saved" information.

When adding a new product with a POST request and metafields in nested data, it works as expected. The body has a structure like:

{product: variants:[{metafields: [{},{}]}]}


But it also does not accept updates.

After searching this forum and documentation, I found an endpoint that will return all metafields for a resource:

GET /admin/api/2024-04/variants/808950810/metafields.json

It returns 200 with all metadata. Someone on the forum said it can accept a PUT request, but every structure I try to send returns a 406 - Not acceptable response.

Then I tested the last part from the documentation. From the above endpoint, I can obtain the ID for the metafield value object. If I have the ID, I can try to update only this value.

PUT /admin/api/2024-01/variants/808950810/metafields/41959940456773.json



    "metafield": {
        "id": 41959940456773,
        "namespace": "custom",
        "key": "symbol",
        "value": "TP_SM-asdasdasdasdasdasd",
        "owner_id": 808950810,
        "owner_resource": "variant",
        "type": "single_line_text_field"


Yes, it works.

But if I have 20 custom fields on my variant, I don't want to make 20 requests to update each value in separate requests. Is there any method to update multiple metafields in one PUT request?



The ID numbers provided in the examples are not correct. You can trust that they were provided correctly.


If more information is needed, please explain what additional information I should provide? Support referred me to the forum.



Replies 0 (0)