Jump to content

Add new Product with WebService [400 Bad Request]


ale93p

Recommended Posts

Hi guys i'm trying to add a new product via web services using the PSWebServiceLibrary, i tried to read other posts in this forum but i have problems.

 

That's my code:

function AddProduct($root_path, $authentication_key, $id, $name, $desc, $cat, $qta, $price){
	try{
		$webService = CreateWebServer($root_path,$authentication_key);
		$xml = $webService->get(array('resource' => 'products?schema=synopsis'));
	}catch(PrestashopWebserviceException $ex){
		echo $ex->getMessage();
		return -1;
	}
	
	
	$resources = $xml->children()->children();
	
	unset($resources->position_in_category);
	unset($resources->manufacturer_name);
	
	$resources->price = floatval($price);
	$resources->quantity = intval($qta);
	$resources->link_rewrite->language[0][0] = str_replace(' ','-',$name);
	$resources->name->language[0][0] = $name;
	$resources->description->language[0][0] = $desc;
	
	$node= dom_import_simplexml($resources->description->language[0][0]);
	$no = $node->ownerDocument;
	$node->appendChild($no->createCDATASection($desc));
	
	$resources->associations = '';
	
	//echo $xml->asXML();
	try{
		$opt = array('resource' => 'products');
		$opt['postXml'] = $xml->asXML();
		$xml = $webService->add($opt);
	}
	catch(PrestaShopWebserviceException $ex)
	{
                echo $ex->getMessage();
	}
	return 0;
}

When I run this funcion it gives me error: 

 

This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request.

 

 

I think there's a sort of problem with the "required=true" parameters, but i don't know what to do.

 

Thanks.

Edited by ale93p (see edit history)
Link to comment
Share on other sites

  • 2 weeks 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...