MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
940 stars 279 forks source link

Can't update product variant metafields #593

Closed ikudosi closed 1 year ago

ikudosi commented 1 year ago

I'm trying to do the following and it doesn't seem to be doing anything:

await service.productVariant.update(32255644270627, {variant: {id:32255644270627, metafields: [{ namespace: "custom_fields", key: "est_in_stock_date", value: "7/4/2023", type: "single_line_text_field" }]}})

I do get a successful response, though no update occurred when I postman for the metafields on that variant.

I'm looking at the docs and it does seem like you can pass metafields in the variant PUT:

curl -d '{"variant":{"id":808950810,"metafields":[{"key":"new","value":"newvalue","type":"single_line_text_field","namespace":"global"}]}}' \
-X PUT "https://your-development-store.myshopify.com/admin/api/2022-10/variants/808950810.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"
ikudosi commented 1 year ago

So unfortunately, after testing, it only creates but not updates. The true way to update existing metafields seems to be to have the reference of the actual ID and use the PUT metafields API.