Product/Variant Metafield Update Strategies/Approaches

Shopify Partner
13 0 1

So been doing research on how to update Metafields in an efficient manner. It looks like there are 2 main ways. Hoping someone's tackled this in an amazing way!!

1. if we know the actual metafield ids we can simply do a PUT to /admin/products/{PRODUCTID}.json with a Metafields array of metafields with their id, as part of the product object. only issue is we need to have the metafield ids, which currently we don't have without making another call to Shopify API to get them and map them based on KEY. Would be great if there was some sort of Shopify end point where we could return a specific Metafield ID based on PRODUCT ID and METAFIELD KEY. (Is there one?)

"metafields": [
            {
                "id": ###,
                "value": "Updated Text",
                "value_type": "string",
            },
            {
                "id": ###,
                "value": "Updated Text",
                "value_type": "string",
            },

            .....

]

2. it seems we can actually do a POST to /admin/products/{PRODUCTID}/metafields.json, but for some reason we can only send a single metafield to this endpoint (i can't actually find any documentation on this end point anywhere), i think its really supposed to be used as a GET to just return all metafields for that PRODUCTID. but POSTING a single metafield, seems to somehow do an UPDATE to that metafield if the KEY matches. Does anyone know if there is a way to POST more than 1 metafield to this endpoint??? Or something similar, vs looping through a bunch of metafields and making individual calls. Only reason we're looking at this approach is we actually don't have the Metafield IDs for the 1st approach.

{
    "metafield": 
        {
            "namespace": "NAMESPACE",
            "key": "KEY",
            "value": "Updated Text",
            "value_type": "string"
        }
}

Thanks Kele.

 

1 Like
Highlighted
Shopify Partner
9 0 1

bump. trying to update customer metafields...

0 Likes