With the code below, I am trying to add an item to the cart, but it is throwing the error as in the title of this post.
let variantData = {
'id': 31638158934062,
'quantity': 1,
'selling_plan': 684949550
};
var url = '/cart.js';
fetch(url, {method: 'GET'})
.then(res => res.json())
.then(response => {
console.log('Success:', JSON.stringify(response))
const cart = response;
// Add item to the cart:
var cartToken = cart.token;
var url = window.Shopify.routes.root + 'cart/add.js';
fetch(url, {
method: 'POST',
headers:{
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify(variantData)
})
.then(res => res.json())
.then(response => {
console.log('Success:', JSON.stringify(response))
})
.catch(error => console.error('Error:', error));
})
.catch(error => console.error('Error:', error)
);
Could you please help fix the issue?

