Cart Transform API is Broken (LinesMerge)

The run result in the newest versions and in the docs (since 2025-07) uses names like linesMerge, but that results in the error:

“Expected one of valid values: expand, merge, update, lineAdd. Got: linesMerge”

This happens with both 2025-07 and 2025-10

Basically, the docs show to return a CartTansformRunResult, but it actually needs to be a FunctionRunResult, which the docs do not mention after 2025-04

Hi! Thanks for bringing this up. I took a look at the Cart Transform API documentation and I think there might be a small mismatch in the operation names.

The official Cart Transform API docs at Cart Transform Function API show these operations:

  • lineExpand
  • linesMerge
  • lineUpdate

But your error message mentions: expand, merge, update, lineAdd

Could you help us debug this?

  • Which specific documentation page were you following?
  • Would you mind sharing a snippet of your implementation code?

This will help us figure out if there’s a documentation inconsistency somewhere or if we can point you toward the right implementation approach. The linesMerge operation
should definitely work, so let’s get to the bottom of what’s happening!

Thanks for your patience as we sort this out.

Yes, THATS THE PROBLEM.

The docs do NOT align with the reality when running the function on the store.

The api version is set to 2025-10 (though same on 2025-07), and I get that error when using the CartTransformRunResult type (in Rust). It works when I used the FunctionRunResult, which aligns with the 2025-04 docs.

The function says it is using the expected api version in the partners dashboard, but it was still erroring for an invalid response.

In the 2025-01 version of the API says that you use are supposed to use the term merge in the Shopify Function but the most up to date and stable version of the api (2025-07) it says you are supposed to use linesMerge.

I’m on API version 2025-01 and I’m having the same issue and can’t get my merge command to work.

Here is what my code looks like:

//========== GraphQL Input Data for the Shopify Function

{
  "cart": {
    "lines": [
      {
        "id": "gid:\/\/shopify\/CartLine\/98a6b1a8-f7ec-401b-8287-b124c47c43fb",
        "quantity": 1,
        "bundleId": {
          "value": "5"
        }
      },
      {
        "id": "gid:\/\/shopify\/CartLine\/c6456931-21c8-4f66-8704-eed9314783fa",
        "quantity": 1,
        "bundleId": {
          "value": "5"
        }
      },
      {
        "id": "gid:\/\/shopify\/CartLine\/94714ab5-e458-4fe3-8d04-1c8ee44af690",
        "quantity": 1,
        "bundleId": {
          "value": "5"
        }
      },
      {
        "id": "gid:\/\/shopify\/CartLine\/b04dc235-3904-4643-8640-1a58ae37d680",
        "quantity": 1,
        "bundleId": {
          "value": "5"
        }
      }
    ]
  },
  "shop": {
    "metafield": {
      "value": "{\"parentVariantId\":\"gid:\/\/shopify\/ProductVariant\/51198624563487\",\"bundlesArray\":[{\"name\":\"Test Bundle\",\"id\":5,\"bundle_display_name\":\"\",\"bundle_checkout_title\":\"\",\"status\":\"active\",\"discount_type\":\"percentage\",\"static_discount_value\":\"20\",\"tiered_discounts\":\"[]\"}]}"
    }
  }
}




//========== Run.js file
export function run(input) {
  // Stores cart lines grouped by their bundle ID property
  const groupedItems = {};
  const metafieldData = JSON.parse(input.shop.metafield.value)

  const parentVariantId = metafieldData.parentVariantId
  const bundlesArray = metafieldData.bundlesArray
  const cartLines = input.cart.lines

  //console.log("VALUE OF Metafield Data post-parse", "Parent Gid: " + parentVariantId, "\n", "Bundles Array", bundlesArray)

  cartLines.forEach(line => {
    const bundleId = line.bundleId
    if(!bundleId?.value) return

    //create a new grouping for the bundle id if it doesn't have one yet
    if(!groupedItems[bundleId.value]){
      groupedItems[bundleId.value] = []
    }

    groupedItems[bundleId.value].push(line)
  })

  console.log(JSON.stringify(groupedItems))

  //Seems like this chunk of code is an array of arrays
  const cartOperations = Object.values(groupedItems).map(group => {
    const totalItemsInBundle = group.reduce((sum, line) => sum + line.quantity, 0);
    const bundleId = group[0].bundleId.value;

    const discountPercentage = calculatePercentageDiscount(bundlesArray, bundleId, totalItemsInBundle);
    const updatedBundleTitle = overrideBundleTitle(bundlesArray, bundleId);

    const lineItems = group.map(line => {
      return {
        cartLineId: line.id,
        quantity: line.quantity
      }
    })

    // console.log("Value of Line Items", JSON.stringify(lineItems))
    // console.log("Discount: " + discountPercentage)
    // console.log("Updated Title: " + updatedBundleTitle)

    return{
      merge: {
        cartLines: lineItems,
        //^ Variant ID of the Parent Product for the Bundler Cart Transform
        parentVariantId: parentVariantId,
        price: {
          percentageDecrease: {
            value: discountPercentage
          }
        },
        //Conditional object spread
        ...(updatedBundleTitle && { title: updatedBundleTitle })
      }
    }
  })

  return {
    operations: cartOperations
  }
};


function calculatePercentageDiscount(bundlesArray, bundleId, totalItemsInBundle) {
  const bundleConfig = bundlesArray.find(bundle => bundle.id == bundleId)

  if (!bundleConfig) {
    return 0;
  }
  if (bundleConfig.discount_type === "percentage") {
    return parseFloat(bundleConfig.static_discount_value) || 0;
  }
  if (bundleConfig.discount_type === "tiered_percentage") {
    const tieredDiscounts = JSON.parse(bundleConfig.tiered_discounts);
    const sortedTiers = tieredDiscounts.sort((a, b) => b.minItems - a.minItems);
    const applicableTier = sortedTiers.find(tier => totalItemsInBundle >= parseInt(tier.minItems));
    if (applicableTier) {
      return parseFloat(applicableTier.discount) || 0;
    }
  }
  return 0;
}

function overrideBundleTitle(bundlesArray, bundleId) {
  const bundleConfig = bundlesArray.find(bundle => bundle.id == bundleId);
  return bundleConfig?.bundle_checkout_title || null;
}



//========= Result of the Shopify Function:
{
  "operations": [
    {
      "linesMerge": {
        "cartLines": [
          {
            "cartLineId": "gid:\/\/shopify\/CartLine\/98a6b1a8-f7ec-401b-8287-b124c47c43fb",
            "quantity": 1
          },
          {
            "cartLineId": "gid:\/\/shopify\/CartLine\/c6456931-21c8-4f66-8704-eed9314783fa",
            "quantity": 1
          },
          {
            "cartLineId": "gid:\/\/shopify\/CartLine\/94714ab5-e458-4fe3-8d04-1c8ee44af690",
            "quantity": 1
          },
          {
            "cartLineId": "gid:\/\/shopify\/CartLine\/b04dc235-3904-4643-8640-1a58ae37d680",
            "quantity": 1
          }
        ],
        "parentVariantId": "gid:\/\/shopify\/ProductVariant\/51198624563487",
        "price": {
          "percentageDecrease": {
            "value": 20
          }
        }
      }
    }
  ]
}

And this what the result looks like in checkout:

What should I do to resolve this issue? My code was working just a couple of weeks ago.

Hey @Kevan_Davis just sending another message to make sure you saw my question.
When you get the chance can you take a look at my post and let me know if there is a problem with my Shopify Function code or if there is an issue with API version 2025-01.

Hey, I’m facing the same issue. @Patrick_Pierre did you manage to fix it?

I’m actually, still dealing with this issue right now and I decided that I would try updating my app to the latest API version to see if that will fix it. I really wanted to avoid having to do this update, but let’s see if it’ll work.

I’m gonna update it tonight and let you know if updating works for me.

Update:

I tried updating to the latest API version as well as deleting the cart transform and creating a brand new one and that didn’t work

@Northwrd_Dev I still haven’t managed to figure out what is causing this issue. I decided to delete my Shopify Function and create a new one with the Shopify CLI on API version 2025-07 and still ran into the same issue?

Could you tell me more about your problem and what you have tried on your end?
I’m hoping we can help each other.

Hey, @Northwrd_Dev

I finally figured this out after comparing the Cart Transform to a few other Shopify Functions!

The issue wasn’t the Cart Transform itself, but how the parent product was created. I used a GraphQL mutation and set the product to active, and it looked fine on the store preview, so I thought I was good.

But it turns out the product wasn’t properly registered with the Online Store sales channel. Once I manually added it to that channel, the Cart Transform immediately started working.

I need to go tweak my mutation to make sure the product gets added to the online store sales channel when my app sends the mutation to create the parent product.

Hope this helps anyone else running into the same odd behavior!