Using Shopify JS Buy SDK, unable to remove variant item from cart

435 views Asked by At

I have a button to remove an item from the cart on my cart page, but I'm receiving this error: Variable $lineItemIds of type [ID!]! was provided invalid value.

I've gone through the GraphQL list and tried every single ID, title, and variant, but it still gives me this error. Which ID should I be using and how should I format the ID correctly?

 $('.remove-item').on('click', function() {
    const lineItems = checkout.attrs.lineItems;
    const checkoutId = 'gid://shopify/Checkout/xxxxxxxxxxx';
    var dataid = this.getAttribute('data-id');
    var varid = btoa(lineItems[dataid].variant.id);
    var lineItemsToRemove = [{
        variantId: varid,
        quantity: 1
    }];
    client.checkout.removeLineItems(checkoutId, lineItemsToRemove).then((checkout) => {
    });
});
1

There are 1 answers

0
kfww-dev On BEST ANSWER

After reviewing the documentation, I realized I was adding an id attribute. It should just pass the plain ID.

var lineItemsToRemove = [
    varid2
];

instead of

var lineItemsToRemove = [{
    id:varid2
}];