I am making a POST request to the Shopify API to send the product object to '/cart/add.js' but I keep getting a 400 response. All of the values I am capturing from the form are correct. So it is the structure of my object that is wrong. Here is what the object looks like:
const items = {
products: [
{
quantity: quantity,
id: variantId,
properties: {
"I am a": document.getElementById('i-am-a').value,
"Company Name": document.getElementById('company-name').value,
"Email": document.getElementById('email-capture').value,
},
}
]
};
CodePudding user response:
Had to find this article on the Cart API https://shopify.dev/api/ajax/reference/cart
const data = {
items: [
{
quantity: quantity,
id: variantId,
properties: {
"I am a": document.getElementById('i-am-a').value,
"Company Name": document.getElementById('company-name').value,
"Email": document.getElementById('email-capture').value,
},
}
]
};
the products array should be named items