1

I am Trying to upload image using rest api but it gives

string(116) "{"message":"Consumer is not authorized to access %resources","parameters":{"resources":"Magento_Catalog::products"}}"

My code is

$configProductData=array(
   "product"=>array(
               "sku"=>"ABC_123456",
              "name"=> "My Product Title Listing",
              "price"=> 425.99,
                "status"=>1,
               "visibility"=> 4,
               "typeId"=> "simple",
                  "weight"=> 15,
                  "mediaGalleryEntries"=>array(
                    "mediaType"=>"image",
                       "label"=> "abc_123456_image",

                       "position"=> 0,
            "disabled"=> false,
            "file"=> "http://www.url.to/product.png",
               "content"=>array(
                   "base64EncodedData"=>"string",
                     "type"=> "string",
                     "name"=> "string"


)

               )


          ),
"saveOptions"=> true


);
$product_url= "http://demo.store.com/magento2/project-community-edition/index.php/rest/V1/products";
$productData = json_encode(array('product' => $configProductData));
$setHaders = array('Content-Type:application/json','Authorization:Bearer '.$adminToken);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $product_url);
curl_setopt($ch,CURLOPT_POSTFIELDS, $configProductData);
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);
curl_close($ch);
var_dump($response);

I can create products without any issue.But image upload is not working

2
  • enable ACL permission for that user/resource
    – 95623
    Commented Sep 28, 2016 at 17:09
  • yes i already do that,but not any progress Commented Sep 29, 2016 at 4:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.