Magento 2: How to Upload Category Image via REST API

apimagento2rest apiswagger

Using swagger I am not seeing any interface out of the box that would allow me to upload category images via API calls, in the same fashion as I can do with product images by base_64 encoding them.

Does anyone have a ready module that would allows me to upload category images? or give point me in the right direction.

Best Answer

Unfortunately, there is no endpoint to upload category image, I worked on this case before, and i would like to share my solution

first of all, you need to build a custom endpoint to upload the image to this path (send the data in base64 then save it in this path)

/{magento_root}/pub/media/catalog/category

lets say your image name is your_image.jpg

after you save this image in this path, you can send the data using the standard magento endpoint

/all/V1/categories

{
  "category": {
    "parent_id": "2",
    "name": "cat_name",
    "is_active": true,
    "include_in_menu": true,
    "custom_attributes": [
      {
        "attribute_code": "image",
        "value": "your_image.jpg"
      }
    ]
  }
}
Related Topic