发表帖子以Shopify API,导致400

发布于 2025-01-20 17:51:16 字数 442 浏览 1 评论 0原文

我正在向 Shopify API 发出 POST 请求,将产品对象发送到“/cart/add.js”,但我不断收到 400 响应。我从表单中捕获的所有值都是正确的。所以我的对象的结构是错误的。该对象如下所示:

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

};

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

};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦屿孤独相伴 2025-01-27 17:51:16

必须在卡车API上找到这篇文章

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

https://shopify.dev/api/ajax/ajax/ajax/reference/cart 应该命名项目

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文