shopify - 尝试在 Shopify 中添加变体时出错

标签 shopify variant

我正在尝试向现有产品 ID 添加变体。 下面是我完成的 JSON 请求。但是我收到错误

{"errors":{"variant":"expected Array to be a Hash"}} 

JSON 请求。

{"variant": [{"product_id": 10065509898,"title": "XS\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_XS","position": 1,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "XS","option3": null,"taxable": true,"barcode": "800123054849","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true},{"product_id": 10065509898,"title": "S\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_S","position": 2,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "S","option3": null,"taxable": true,"barcode": "800123054856","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true},{"product_id": 10065509898,"title": "M\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_M","position": 3,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "M","option3": null,"taxable": true,"barcode": "800123054863","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true},{"product_id": 10065509898,"title": "L\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_L","position": 4,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "L","option3": null,"taxable": true,"barcode": "800123054870","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true},{"product_id": 10065509898,"title": "XL\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_XL","position": 5,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "XL","option3": null,"taxable": true,"barcode": "800123054887","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true},{"product_id": 10065509898,"title": "XXL\/ BROWN","price": 49.05,"sku": "BA1015_BROWN_XXL","position": 6,"grams": 0,"inventory_policy": "deny","compare_at_price": null,"fulfillment_service": "manual","inventory_management": "shopify","option1": "BROWN","option2": "XXL","option3": null,"taxable": true,"barcode": "800123054894","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true}]}

我做错了什么?

最佳答案

这是因为您正在发送一系列变体。你必须add each variant分别:

POST/admin/products/{product_id}/variants.json

{
    "variant": {
        "option1": "BROWN",
        "price": "49.05",
        "sku": "BA1015_BROWN_XS"
     }
}

仅当您是 creating a new product 时才可以传递变体数组.

关于shopify - 尝试在 Shopify 中添加变体时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42114761/

相关文章:

c++ - std::variant 可以定义多少种类型?

c# - 无效的变体崩溃

javascript - 如何通过脚本标签将我的 HTML 准确插入 Shopify 商店?

javascript - 点击功能在移动设备上无法正常工作

delphi - 为什么 Delphi 变体不能保存对象?

arrays - Excel VBA : adding a row to a variant array in one line

jquery - 使用 jQuery 从输入字段获取值

shopify - 无法验证请求来源 - Shopify

Shopify 将多个具有不同属性的产品添加到购物车

c++ - 在编译时从变量中获取类型