how can i completely replace my entire cart with differnet line items with cart api in shopify

Hi everyone,

With the deprecation of the Checkout API, I’m transitioning to Shopify’s Cart API. In the Checkout API, we had a simple way to replace the entire cart by passing new line items, but I don’t see a direct equivalent in the Cart API.

From my research, the Cart API provides mutations like:

  • cartLinesAdd (to add new items)
  • cartLinesRemove (to remove specific items)
  • cartLinesUpdate (to update existing items)

However, there doesn’t seem to be a cartLinesReplace or cartReplace mutation. This means that if I want to completely replace the cart with a new set of line items, I need to:

  1. Fetch the current cart items (cart(id: $cartId)).
  2. Remove all existing line items (cartLinesRemove).
  3. Add the new line items (cartLinesAdd).

Is there an efficient way to replace the entire cart in a single API call?

Not in Flow. Flow does not work in checkout.