You can upload product images by REST API Magento with the PUT action and the help of /V1/products/<sku>.
Action: PUT
URL: <BASE_URL>/rest/V1/products/<SKU>
(Example URL: https://magento.test/rest/V1/products/my-sku)
Header: Authorization: Bearer <ADMIN TOKEN>
Payload Body:
{
"product": {
"media_gallery_entries": [
{
"media_type": "image",
"label": "Image Label",
"position": 0,
"disabled": 0,
"types": [
"image",
"small_image",
"thumbnail",
"media_gallery"
],
"file": "rbj1.jpeg",
"content": {
"base64_encoded_data": "<base64_encoded_string>",
"type": "image/jpeg",
"name": "rbj1.jpeg"
}
},
{
"media_type": "image",
"label": "Image Label 2",
"position": 0,
"disabled": 0,
"types": [
"media_gallery"
],
"file": "rbj2.jpeg",
"content": {
"base64_encoded_data": "<base64_encoded_string>",
"type": "image/jpeg",
"name": "rbj2.jpeg"
}
}
]
}
}
In Body Payload,, You need to replace <base64_encoded_string> string with a real image base64 encoded string value.
types field used to display image types like thumbnail, small_image, image, or media_gallery.
You can add an ‘id'(“id”: 120) field in the payload if you want to replace already existing images in the product
A Response will be product data that contains media images.
While you check the product in the backend, you will able to see your images uploaded to the product.
