How to upload image for category through magento 2 rest api. below is my code but image is not getting uploaded.

$CI = "/var/www/html/pradeep/apistest/media/hero/hero.jpg";
$categoryItemData = '{
    "category": {
        "id": 0,
        "parent_id": 0,
        "name": "'.$linkname.'",
        "is_active": true,
        "position": 0,
        "level": 0,
        "include_in_menu": true,
        "extension_attributes": {},
        "custom_attributes": [
                "attribute_code": "image","value": "'.$CI.'"

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $categoryUrl);
curl_setopt($ch,CURLOPT_POSTFIELDS, $categoryItemData);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $setHaders);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
  • what is the error? also "image" is not a custom attribute. – Philipp Sander Feb 20 at 10:25
  • no, not a custom attribute. but i got on google to add in the custom attribute section – Pradeep Sanku Feb 20 at 10:30
  • Could you please try by sending image data in base64 encode. as in customer account we can pass image in base 64 encode. – Hitesh Agrawal Feb 20 at 10:57

Your Answer

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

Browse other questions tagged or ask your own question.