'Making a POST to Shopify API resulting in 400

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,
    },
  }
]

};



Solution 1:[1]

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

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 lachnroll