Unable to add more than 100 Products using Add.js

Topic summary

A developer is encountering a hard limit when adding products to a cart via the add.js API endpoint. Despite attempting to add 150 products, only 100 are successfully added.

Current Implementation:

  • Products are split into batches of 50 variant IDs
  • Each batch is sent sequentially via POST to /cart/add.js
  • A 500ms delay is implemented between batch requests
  • After all batches complete, the page redirects to /cart/

The Problem:
The code appears incomplete (cuts off mid-function), but the core issue is clear: there’s a 100-item ceiling regardless of the batching strategy used.

Likely Cause:
This suggests a platform-imposed cart line item limit (common in e-commerce platforms like Shopify, which has a 100-line-item maximum per cart).

Status:
The issue remains unresolved with no responses yet. The developer needs confirmation whether this is a platform limitation or a code implementation problem.

Summarized with AI on November 22. AI used: claude-sonnet-4-5-20250929.

I am trying to add more than 100 products to cart using add.js but is unable to do so, if I try to add 150 products to cart only 100 gets added for some reason. Here is the code I am using -

function addToCart(variantIds) {
  const batchSize = 50;
  const batches = [];

  // Split the variant IDs into batches of batchSize
  for (let i = 0; i < variantIds.length; i += batchSize) {
    const batch = variantIds.slice(i, i + batchSize);
    batches.push(batch);
  }

  // Define a function to add a single batch to the cart
  function addBatch(batch) {
    const data = {
      items: batch.map(variantId => {
        return {
          id: variantId,
          quantity: 1
        };
      })
    };

    fetch('/cart/add.js', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data)
    })
    .then(response => {
      return response.json();
    })
    .then(data => {
      // Wait for 500ms before adding the next batch
      setTimeout(() => {
        addNextBatch();
      }, 500);
    })
    .catch(error => {
      console.error(error);
    });
  }

  // Define a function to add the next batch to the cart
  function addNextBatch() {
    if (batches.length > 0) {
      const batch = batches.shift();
      addBatch(batch);
    } else {
      // If all batches have been added, redirect to the cart page
      window.location.href = '/cart';
    }
  }

  // Start adding batches from the first batch
  addNextBatch();
}