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

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

bhavik_
Shopify Partner
2 0 2

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?

Reply 1 (1)

paul_n
Shopify Staff
1771 194 414

Not in Flow. Flow does not work in checkout. 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.