2

I am getting below error while hit REST API from postman:

"message": "The product can't be saved.",

I have used below details for API:

URL: magento.localhost/rest/V1/products/p1/media

HEADERS :

Content-Type:application/json

Authorization:Bearer 1si2ch4k8to78ytx14is8gcgfs4p3glk

BODY

{  
   "entry":{  
      "id":153,
      "media_type":"image",
      "label":"test",
      "position":0,
      "disabled":true,
      "types":[  
         "image"
      ],
      "file":"test.png",
      "content":{  
         "base64_encoded_data":"base64_encoded_data",
         "type":"image/png",
         "name":"new image"
      }
   }
}

Can anyone please help me in this? I tried lot of thing but nothing is working.

2 Answers 2

1

Make sure the product you are using has all the required fields saved to the product before trying to upload the image via the rest API.

In our case the price of the product was missing, which caused a validation failure in Magento 2.

Note that this will apply to any custom required attribute as well.

2
  • I tried to save the product in the magento admin and an error showed up. In my case a custom attribute was missing. Fixed the issue and it worked.
    – Memonic
    Commented Sep 17, 2019 at 14:36
  • I have added your comment to the solution as well
    – master
    Commented Sep 18, 2019 at 9:00
0

Related issue, terrible log message it must say why. https://github.com/magento/magento2/issues/26053

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.