Jump to content

Update manufacturers via API


good_nabuco

Recommended Posts

Hello everybody

 

I would like to update the manufacturers via API.

 

I tried to use this code:

require_once('./PSWebServiceLibrary.php');

...

foreach ($resources as $nodeKey => $node)
{
	$resources->$nodeKey = $_POST[$nodeKey];
}
//web service call
try
{
	$opt = array('resource' => 'manufacturers');
	$opt['putXml'] = $xml->asXML(); 
	$opt['id'] = $id_c;
	$xml = $webService->edit($opt);
}
catch (PrestaShopWebserviceException $ex)
{
        // 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();
}

...

This error is generated from the web service library, precisely from the 'edit' function:

...	 
        public function edit($options)
	{		
		$xml = '';
		if (isset($options['url']))
			$url = $options['url'];
		elseif ((isset($options['resource'], $options['id']) || isset($options['url'])) && $options['putXml'])
		{
			$url = (isset($options['url']) ? $options['url'] : $this->url.'/api/'.$options['resource'].'/'.$options['id']);
			$xml = $options['putXml'];
			
			if (isset($options['id_shop']))
				echo $url .= '&id_shop='.$options['id_shop'];
			if (isset($options['id_group_shop']))
				$url .= '&id_group_shop='.$options['id_group_shop'];
		}
		else
			throw new PrestaShopWebserviceException('Bad parameters given');
		
		$request = self::executeRequest($url,  array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => $xml));
		self::checkStatusCode($request['status_code']);// check the response validity
		return self::parseXML($request['response']);
	}
...

Anybody can tell me how I can solve this problem?

 

Thank you!

Edited by good_nabuco (see edit history)
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...