I have a custom quiz in which I need to implement adding to cart. Now the problem is that in the console there is a 404 error and a message - {“status”:“bad_request”,“message”:“Parameter Missing or Invalid”, “description”:“Required parameter missing or invalid: items”}. But in my function I use the console and the data looks like this:
There is a product with this ID. I also added input type hidden to the form in the value of which I write down this ID. In the console, it is also correctly entered. What could be the problem?
Since you are trying to add multiple items to the cart at once, the Shopify AJAX API /cart/add.js route only supports adding a single item at a time. Instead, you should iterate through the items array and call the API for each item individually.
This code iterates through each item in the formData.items array and makes a separate API call for each item. Make sure your formData object has the correct format:
```markup
```javascript
{
"items": [
{
"id": 6847507988526,
"quantity": 3
}
]
}
After making these changes, the code should work as expected and add the items to the cart without any error.