Jump to content

Update products by webservice


Recommended Posts

Hi,

I try to update a product with the webservice but no way, always got : 400 Bad request.
On customer i have no problem, it's only on products.
My Prestashop is a new install, version 1.7.

I use https://github.com/PrestaShop/PrestaShop-webservice-lib for an easy way.

There is my code :

define('DEBUG', true);
define('PS_SHOP_PATH', 'http://prestashopdomain.com');
define('PS_WS_AUTH_KEY', '8XKBE7ZK3ZSRExxxxxxxxxQLR2MXF');
require_once('./PSWebServiceLibrary.php');

$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);

$opt = array('resource' => 'products');
$opt['id'] = '1';
$xml = $webService->get($opt);
$resources = $xml->children()->children();
$resources->reference = 'demo_3b';
$opt = array('resource' => 'products');
$opt['putXml'] = $xml->asXML();
$opt['id'] = '1';
try {
	$webService->edit($opt);
} catch (PrestaShopWebserviceException $ex)
{
	echo $ex->getMessage();
}

As you see, nothing particular...

Can somebody help me ? Thanks :-)
 

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...

Hi Echomeme,

you need to remove some data from your schema before update request

  unset($xml->children()->children()->manufacturer_name);         //mandatory            
  unset($xml->children()->children()->quantity);                  //mandatory
 

because this values are read only.

PS: better to write one function to get product xml

and another to update product



  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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...