Line item key changing if add/update/delete multiple products at same request with CART API

Topic summary

Developers reported that Shopify’s Cart API was unexpectedly changing line item keys when adding, updating, or deleting multiple products in a single request. The key would change after the second request but remain stable afterward, breaking functionality like item removal and quantity updates.

Core Issue:

  • Line item keys changed inconsistently during cart operations
  • Affected /cart/add.js, /cart/update.js, and /cart/change.js endpoints
  • Caused “no valid id or line parameter” errors when attempting to remove items
  • Page refresh would correct the keys, suggesting a server-side synchronization problem

Impact:

  • Remove links generated by {{item.url_to_remove}} failed until page refresh
  • Cart drawer/side cart implementations showed duplicate line items instead of merged quantities
  • Discount application/removal also triggered key changes

Resolution:
Shopify Support confirmed and fixed the bug after being contacted through their partner support channel. Multiple users verified the fix is working.

Additional Finding:
One developer discovered that passing boolean values as strings in line item properties can still cause key mismatches, as Shopify converts them to actual booleans server-side, creating temporary hash differences until the page refreshes.

Summarized with AI on October 29. AI used: claude-sonnet-4-5-20250929.

Same issue here. The item.key changes on existing products in the cart for me anytime a new product is added. As these keys are used to manage connections between products in the cart this is causing issues. Hopefully someone from Shopify can confirm if this is expected behaviour as it appears it wasn’t in the past.

2 Likes