Jump to content

Add image to product in Prestashop 1.7 using WebServices


betox033

Recommended Posts

I am trying to add a Product to Prestashop using WebService. So far he was able to create the product, assign it to its corresponding category and modify the stock without major problems, however, you will not be able to add an image to the product.

I am based on this:

https://github.com/xabikip/PrestaShopWebService/blob/master/examples/createProduct.php

But I also tested the official documentation:
https://devdocs.prestashop.com/1.7/development/webservice/tutorials/change_product_image/

Below is the code: 

 $url = $url . '/api/images/products/' . $id_producto;

  $image_path = 'http://localhost/webservice/img/caja.jpg';

  echo("<br>" . $image_path); 
  echo("<br>" . $url);


  $ch = curl_init();
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_USERPWD, $key.':');
  curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path.';type=image/jpg'));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $result = curl_exec($ch);
  curl_close($ch);

Is there any data that I am not taking into account, any data that is wrong?

  • Thanks 1
Link to comment
Share on other sites

  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...