Shopify API 2025-04: Avoid Metafield Loss When Using productSet

Shopify API 2025-04: Avoid Metafield Loss When Using productSet

kevin-karin
Shopify Partner
1 0 1

I'm using the Shopify GraphQL Admin API (version 2025-04) and the productSet mutation to update or create products. However, I’ve noticed that if I don’t include existing metafields in the request, they get deleted.

To prevent this, my current approach is:

  1. Fetch existing metafields using a GraphQL query.

  2. Merge them with the new metafields I want to add.

  3. Send everything back in productSet.

The issue is that while I’m fetching the metafields, they might have been updated externally, meaning I could end up sending outdated data and unintentionally overwriting recent changes.

My Questions:

  • Is there a way to use productSet without affecting existing metafields?

  • If not, is there an alternative method to update metafields separately without deleting them?

  • What’s the best practice for ensuring metafields remain intact while updating products?

Reply 1 (1)

Tchinkatchuk
Shopify Partner
2 0 0

I have the same problem myself.
It's suprising that you can't use upSert and CustomId without “emptying” the existing metafields.
The solution, which is to retrieve the metafields upstream and send them back, only works if no changes are made to the Shopify data during the time-lapse between retrieval and push.
I doubt we're the only ones to encounter these issues.
Any feedback would be appreciated.