0

I am trying to add an image to a product in Magento 2.1 via the REST API using the catalogProductAttributeMediaGalleryManagementV1 service. The request is a POST request to https://example.com/rest/V1/products/$000000000093/media where $000000000093 is the sku of the item I am trying to add the image to. The body of the request is

{
  "entry":{
     "types":[
        "image",
        "thumbnail",
        "small_image"
      ],
      "label":"Image",
      "media_type":"image",
      "disabled":false,
      "content":[
        {
          "type":"image\/jpeg",
          "name":"Test123.jpg",
          "base64_encoded_data":"\/9j\/4AAQSkZJRgABAQAA..."
        }
     ],
   "position":1,
   "file":"\/t\/e\/Test123.jpg"
 }
}

This returns a 500 code and checking the Magento exception.log you get the following error:

main.CRITICAL: exception 'LogicException' with message 'Property "0" does not have corresponding setter in class "Magento\Framework\Api\Data\ImageContentInterface".'

1

Look like you need to define content field as object, not array.

Try to use:

"content": {
    "type":"image\/jpeg",
    "name":"Test123.jpg",
    "base64_encoded_data":"\/9j\/4AAQSkZJRgABAQAA..."
},

Source: \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface

  • Ah ha, working now. It's always something simple... thank you, spent way too long on this. – SD252 Jan 16 '17 at 14:43

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.