magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

Price is empty when creating a product via REST API #3680

Closed neran closed 8 years ago

neran commented 8 years ago

When I POST /V1/products with these example parameters: {"product":{"sku":"13744-SG-H-CP23","name":"Handmade Safed Hanukah Candles - Bright Fire","price":"13.00","status":1,"attributeSetId":4,"options":[]}}

The product is created but the price is empty: http://prntscr.com/accys0

Using PUT - same result.

If I POST again with the same parameters - the price is updated! Going crazy, what am I missing?

Thanks in advance.

antsem88 commented 8 years ago

Try to set the price in the request as int, not as string (without quote).

neran commented 8 years ago

Still the same without quotes: {"product":{"sku":"13744-SG-H-CP23","name":"Handmade Safed Hanukah Candles - Bright Fire","price":13,"status":1,"attributeSetId":4,"options":[]}}

degaray commented 8 years ago

Try to add the product type in your request

neran commented 8 years ago

Is it this parameter? typeId (string, optional): Type id Which value for simple product? "Simple Product"?

degaray commented 8 years ago

Try something like this:

{
  "product": {
    "sku": "AN_SKU_FOR_YOU",
    "name": "For You",
    "attributeSetId": 9,
    "price": 12.5,
    "status": 1,
    "visibility": 4,
    "typeId": "simple",
    "weight": 0,
    "extensionAttributes": {
      "stockItem": {
        "stockId": 1,
        "qty": "1",
        "isInStock": true,
        "isQtyDecimal": false,
        "useConfigMinQty": true,
        "minQty": 0,
        "useConfigMinSaleQty": 0,
        "minSaleQty": 0,
        "useConfigMaxSaleQty": true,
        "maxSaleQty": 0,
        "useConfigBackorders": false,
        "backorders": 0,
        "useConfigNotifyStockQty": true,
        "notifyStockQty": 20,
        "useConfigQtyIncrements": false,
        "qtyIncrements": 0,
        "useConfigEnableQtyInc": false,
        "enableQtyIncrements": false,
        "useConfigManageStock": true,
        "manageStock": true,
        "isDecimalDivided": true,
        "stockStatusChangedAuto": 0,
        "extensionAttributes": {}
      }
    },
    "options": [],
    "tierPrices": [],
    "customAttributes": []
  },
  "saveOptions": true
}

Obviously use your own preferences specially your attribute set. This one works for me.

neran commented 8 years ago

Perfect! Works! typeId did it. Thank you!!

evolic commented 5 years ago

Works! Adding typeId did it. In my case there where missing also some custom attributes, not only the price. Thank you!!