Jump to content

[SOLVED] API Update Product Quantity Problem


Recommended Posts

Hi,

I'm trying to update just the product quantity for a given product via the Prestashop 1.6 API from a PHPdesktop bridging product synchronising app I'm making.

 

Have been able to get the data from the shop but not update it.

 

I get the following error which suggests its to do with the data I'm sending:

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

 

This is what I have for the Update side:

function updateProduct($id, $qunatity){
	$id = (int)$id;
	$qunatity = (int)$qunatity;
	if(isset($id) && isset($qunatity)){
		$xml = simplexml_load_string(
'<?xml version="1.0" encoding="UTF-8"?>        
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">    
   <product>
		<id><![CDATA['.$id.']]></id> 
		<quantity notFilterable="true"><![CDATA['.$qunatity.']]></quantity>
  </product>
</prestashop>');
		// Call the web service
		try{
			$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
			$opt = array('resource' => 'products');
			$opt['putXml'] = $xml->asXML();
			$opt['id'] = $id;
			$xml = $webService->edit($opt);
			echo "Successfully updated.";
		}catch (PrestaShopWebserviceException $ex)			{
			// Dealing with errors
			$trace = $ex->getTrace();
			if ($trace[0]['args'][0] == 404) echo 'Bad ID';
			else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
			else echo 'Other error<br />'.$ex->getMessage();
			$canProceed = 0;
		}
	}
}

Any ideas as to were I'm going wrong?

 

Thanks

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

Hi Totti,

Debug is enabled.

No errors coming up on the error file.

On the script file displaying the http calls and returns the Return Body is:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[93]]></code>
<message><![CDATA[parameter "quantity" not writable. Please remove this attribute of this XML]]></message>
</error>
</errors>
</prestashop>

and the error message is:

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

 

The xml that is sent is:

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">    
   <product>
		<id><![CDATA[45]]></id> 
		<quantity>222</quantity>
  </product>
</prestashop>

I have another script as well that modifies XML via a GET before PUTTING it and it has the same error "quantity" not writable.

 

The site uses Advanced Stock control. There must be a way to update the quantity.

 

Thanks

Link to comment
Share on other sites

There is an XML error code returned:

XML error code 93 is the table is not present in the descriptor. I thought this was done by including "$opt = array('resource' => 'products');"

 

It is a good chance that this is the issue however, I do not know how to correct it.

 

Any ideas?

 

Thanks

Link to comment
Share on other sites

Hi Totti,

Thanks for the assistance.

I am able to update stock_availables, however, the quantity also needs to be changed in the products table. Quantity is stored in two locations.

 

As I can't update it in the products table via the API I might just do a direct DB update on the different tables.

 

Thanks again.

Link to comment
Share on other sites

Updating physical stock quantities via the webservice is more difficult than one fist thinks so I have closed this and started a new one that asks what updates are required. I've noted a few people asking this over the web so hopefully it will end up helping people out.

https://www.prestashop.com/forums/topic/451883-how-do-you-use-the-webservice-api-to-increase-physical-stock/
  • Like 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...