1

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.

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.

|improve this answer|||||
  • 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 Sep 17 '19 at 14:36
  • I have added your comment to the solution as well – master Sep 18 '19 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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