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

Error when trying to add a variant in Shopify

我正在尝试向现有产品 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 时才能传递变体数组。