cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 API creat product width multiple images

Magento 2 API creat product width multiple images

I would like to create a product with several images via API.

It also works but he only reads one picture. The others pictures only show the default thumbnail in the Magento backend.

 

He fetches the images via foreach:
foreach($_POST['image'] as $key => $value) {

  $path_parts = pathinfo($value);

  $image[] = array(
      'id' => $key,
      'media_type' => 'image',
      'label' => 'Product Image '.$key,
      'position' => $key,
      'disabled' => 'false',
      'types' => array('image','small_image','thumbnail'),
      'file' => $path_parts['filename'].'.'.$path_parts['extension'],
      'content' => array(
        "base64_encoded_data" => base64_encode(file_get_contents($value)),
        "type" => "image/jpeg",
        "name" => $path_parts['filename'].'.'.$path_parts['extension']
      )
    );
}
and then output in the post
$post ='{
  "product": {
    "sku": "DS12342134",
    "name": "Test",
    "attribute_set_id": 4,
    "price": 25,
    "status": 1,
    "visibility": 1,
    "type_id": "simple",
    "weight": "0.5",
    "media_gallery_entries":
      '.json_encode($image).'
    ,
  }
}';

can someone help?
1 REPLY 1

Re: Magento 2 API creat product width multiple images

Hello @Ibu500 

Greetings!

 

I can not find any error in the code, but one thing to check is all used images format.

All the images format is same or not that once you varify. It may works.

 

All the best!

 

Accept as solution if it goes right!

 

Stay healthy!