Jump to content

Recommended Posts

Estou tentando enviar este xml de exemplo mais estou tendo erro:

 

Fatal error: Uncaught exception 'PrestaShopWebserviceException' with message 'This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request.' in C:\xampp\htdocs\prestashop\coletor\webservice\PSWebServiceLibrary.php on line 91

<?php
$webx = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<customer>
	<id><![CDATA[2]]></id>
	<id_default_group xlink:href="http://localhost/prestashop/api/groups/3"><![CDATA[3]]></id_default_group>
	<id_lang xlink:href="http://localhost/prestashop/api/languages/1"><![CDATA[1]]></id_lang>
	<newsletter_date_add><![CDATA[2013-12-13 08:19:15]]></newsletter_date_add>
	<ip_registration_newsletter></ip_registration_newsletter>
	<last_passwd_gen><![CDATA[2016-02-15 08:26:58]]></last_passwd_gen>
	<secure_key><![CDATA[55303df030c6cbb38ae9cd601ddbbe96]]></secure_key>
	<deleted><![CDATA[0]]></deleted>
	<passwd><![CDATA[f2e112588758e00b02e5f48f69866e7b]]></passwd>
	<lastname><![CDATA[DOE]]></lastname>
	<firstname><![CDATA[John John]]></firstname>
	<email><![CDATA[[email protected]]]></email>
	<id_gender><![CDATA[1]]></id_gender>
	<birthday><![CDATA[1970-01-15]]></birthday>
	<newsletter><![CDATA[1]]></newsletter>
	<optin><![CDATA[1]]></optin>
	<website></website>
	<company></company>
	<siret></siret>
	<ape></ape>
	<outstanding_allow_amount><![CDATA[0.000000]]></outstanding_allow_amount>
	<show_public_prices><![CDATA[0]]></show_public_prices>
	<id_risk><![CDATA[0]]></id_risk>
	<max_payment_days><![CDATA[0]]></max_payment_days>
	<active><![CDATA[1]]></active>
	<note></note>
	<is_guest><![CDATA[0]]></is_guest>
	<id_shop><![CDATA[1]]></id_shop>
	<id_shop_group><![CDATA[1]]></id_shop_group>
	<date_add><![CDATA[2016-02-15 14:26:58]]></date_add>
	<date_upd><![CDATA[2016-02-15 17:02:59]]></date_upd>
<associations>
<groups nodeType="group" api="groups">
	<group xlink:href="http://localhost/prestashop/api/groups/3">
	<id><![CDATA[3]]></id>
	</group>
</groups>
</associations>
EOT;

define('DEBUG', true);											// Debug mode
define('PS_SHOP_PATH', 'http://localhost/prestashop/');		// Root path of your PrestaShop store
define('PS_WS_AUTH_KEY', 'BQ5BXIJEU4CVI3LWXDRJKJ2W77QVPY1V');	// Auth key (Get it in your Back Office)
require_once('../PSWebServiceLibrary.php');

$gateway = 'customer';

$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$xml = $webService->get(array('url' => PS_SHOP_PATH . '/api/' . $gateway . '?schema=blank'));

$opt = array('resource' => $gateway);
try {
	$opt['postXml'] = $webx;
	$xml = $webService->add($opt);
}
catch (PrestaShopWebserviceException $ex) {
	// Aqui estamos lidando com erros
	$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 '<b>Other error: </b>' . $ex->getMessage().'<br />';
	}
}
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...