Magento 2.1.5 REST API – Media Upload Image Not Saving

magento2media

Working on Magento version – 2.1.5.

Hello Techies

I am working on magento 2 project and learning rest api .

I am trying to upload product image via rest api .

Url of rest api = http://127.0.0.1/megento2/index.php/rest/V1/products/{sku}/media.

Method i used POST as mention in magento 2 dev docs.

Below are the parameters :

[
  {
    "id": 0,
    "media_type": "test",
    "label": "test",
    "position": 0,
    "disabled": true,
    "types": [
      "thumbnail"
    ],
    "file": "test.png",
    "content": {
      "base64_encoded_data": "Here i have passed base64_encoded data of image",
      "type": "file/png",
      "name": "test.png"
    },
    }
  }
]

Not sure why but getting 400 Error and error message is like below :

Product could not be saved

Your help will be appreciated .

Best Answer

Its because of Price field of the product.

Follow the below steps :

  • Logged in with your magento 2 admin
  • Edit the same product for which trying to upload image by rest api
  • Check price is added or not ? Price field is blank and thats why you have face this issue .
  • Add Price for that product and Save the product
  • Clear the cahe and your issue get resolved.

For more details refer this link - https://github.com/magento/magento2/issues/5728

Related Topic