2017-02-08 8 views
1

Ich versuche, eine Variante der bestehenden Produkt-ID hinzuzufügen. Unten ist die JSON-Anfrage, die ich gemacht habe. Allerdings erhalte ich einen FehlerFehler beim Hinzufügen einer Variante in Shopify

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

JSON Anfrage.

{"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": "80","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": "80","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": "80","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": "80","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": "80","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": "80","inventory_quantity": 0,"old_inventory_quantity": 0,"inventory_quantity_adjustment": 1,"weight": 1,"weight_unit": "lb","requires_shipping": true}]} 

Was mache ich falsch?

+0

Mit welcher URL führen Sie einen REST-Anruf durch? Ist es PUT oder POST? Gibt es bereits vorhandene Varianten im Produkt? – HymnZ

Antwort

1

Es ist weil Sie eine Reihe von Varianten senden. Sie müssen add each variant getrennt:

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

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

Sie können nur eine Reihe von Varianten geben, wenn Sie creating a new product sind.

+0

Sie können auch mehrere Varianten mit "PUT" auf dem Produkt hinzufügen. – HymnZ

+0

@HymnZ sei vorsichtig, weil es bestehende Varianten ersetzen wird. –

+0

Nein .. Sie können bestehende Varianten mit den neuen Varianten beibehalten, wenn Sie variante IDs im Array bereitstellen. Eine raffinierte versteckte Funktion. – HymnZ

Verwandte Themen