2

I'm trying to create simple product using REST API.

Product is created but having issues with Images.

Here is my JSON for it.

{
  "product": {
  "attribute_set_id": 4,
  "type_id": "simple",
  "sku": "B201-SKU",
  "name": "B201",
  "price": 25,
  "status": 1,
  "custom_attributes": {
    "description": "Heavy Duty Brake Cables",
    "meta_description": "Some describing text",
    "image" : "error.png",
    "small_image": "error.png",
    "thumbnail": "error.png"
   }
  }
 }

Note: I've uploaded image under pub/media/catalog/product

When i open products grid at admin, Image is displayed there. Take a look at below.

Admin Grid

Also when i click at grid on Image it showing image is Popup !!!!

But when i open that product image is not there as well as at Frontend.

Also executed upgrade,cache,indexer commands but image is not showing both ends.

What is missing ?? Any one has idea about this ??

Thanks in Advance.

1

the best approach to send the image content encoded by base64 instead of using your way,

try this code and optimize it as you want, this code will create the product with image encoded by base64

{
  "product": {
    "attribute_set_id": 4,
    "type_id": "simple",
    "sku": "B201-SKU",
    "name": "B201",
    "price": 25,
    "status": 1,
    "media_gallery_entries": [
      {
        "label": "",
        "position": 0,
        "disabled": false,
        "types": [
          "image",
          "small_image",
          "thumbnail"
        ],
        "content": {
          "type": "image/png",
          "name": "GN271.png",
          "base64_encoded_data": "iVBORw0KGgoAAAANSUhEUgAAAV4AAAEsBAMAAAB578bjAAAAG1BMVEXMzMyWlpaxsbG3t7e+vr6qqqrFxcWjo6OcnJx35/fKAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADFUlEQVR4nO3az2/TMBjGcXdt0x6pWGmOY5oQR0Bi4pgWIXGkgoodi5B2XgGxKxUa/NvE+enXTVszLd076fs5zU7tPsoS23FqDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHBbs8/r+Prj8r5jBIouRpn42eG/++mowQtjOpu1J5ttisBHTZ081pL3fV0VL/Xn7W2GUp13KioT7Xmjtaj8oz3vQFZOtOd9af+8OV9Gby/Kzx4y77tFIf2Gcfl3kuddSEnWwF4Ov/O2b2ysX+kfvfIjc6fVp1byVtJveuQUbd6mj9nRYVwW7D/n2D26rVULAvP2R87E0S0v4H2tWhCYtyMSpic49o4qy5uOvk/qkh0slgGtWhCYNz2jV3WpVwwQ+1q1IDDvXAZMR4sPAa1aEJh3VUzBhbk43QrzruUFO30Aed3il3zC2NeqBYF5vQHhIeRNnGJ/sdB9v63l+OBRmfeqqX53qxaEj7/HTfW7W7UgfH6bNNXvbtWCwLzpgDD6ubUTfXmHdo3+Y1sn+vJ2s2ed8XlzJ/rymuLx+FvSdPB+80rL/EC1/dC03acwb7eqmJxtdKIwb/5An7tJvE405o1Wdd0kkZ1ozGu6zo7UWHaiMq+Jnte1cu7QmdeYr/PqihCdaM1rzKy8it3lr8b5ohS9zvOKbT3FedP7LjvFyvd3XPl9p3u/RIjsbaf7eV6yk7OznaY+r33ccG849XmHcopTl/fo9PRElOWMoS5vR16vdkM1lod15R16eSPleQf+9oP8mMa88r2a8rx9b8mr/Xo48hYMPeXjg33Bkjhl7eNZ5K14B8rnC7td4g4QU1nUl3de/Qgms77VLH4XAvNOxTPmQP160iasTnC2FaFnve79/iG7z7LtqHEeOFuuK3oe8uSHs82SydmluXy1Uva82Zh36tWKty8K83ZlpTtYqMxrRzSHWF2qzCt+DCVPr8q87gaw3I1Smjeqr4jvXicHzPsfqsBb32tpM7tex3+bXxEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAO7UP04luo8JE2YqAAAAAElFTkSuQmCC"
        },
        "media_type": "image"
      }
    ]
  }
}

I always use this way

Your Answer

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