'Shopify add/remove items from cart attributes

i have problems adding/removing items from shopifys cart attributes. Following the documentation for that i basically copied and slightly edited this code:

let formData = {
 'items': [{
  'id': 36110175633573,
  'quantity': 666
  }]
};

  let addAttributeResponse = fetch(window.Shopify.routes.root + 'cart/add.js', {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify(formData)
  })
  .then(response => {
    console.log("Add attribute to card success response: ", response);
    return response.json();
  })
  .catch((error) => {
    console.error('Error:', error);
  });

I get within the success block an 404 Not Found Error:

enter image description here

Does anyone have an idea why this fails? My goal is basically to remove some attributes which are added before. I have attributes which are customizations for products. But when a user adds a product to the cart, and then removes it, the attribute i added before is still there and if he buys another product i have the old (not needed) attribute inside my order.

Any tips would be great. Thank you!



Solution 1:[1]

I have tried that code on my store and it works just fine. You can find more details about the issue in Network Tab in the developer tools in the request's response.

404 status code indicates that you are using the wrong variant id. Please make sure that you did not confuse it with product id which is different or double-check the variant id.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TwistedOwl