tom56 Posted August 6, 2015 Share Posted August 6, 2015 (edited) Bonjour, Je rencontre un problème pour ajouter un magasin par webservice. Je récupère bien un objet store que je remplis avec mes informations mais au moment de l'ajouter je rencontre une erreur 400 This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request. Voici le code que j'utilise // Ajout de la boutique dans PrestaShop try { $webService = new PrestaShopWebservice($urlPrestashop, $apiKey, $debugMode); $opt['resource'] = 'countries'; $opt['filter']['iso_code'] = $countryDO->getAlpha2(); $xml = $webService->get($opt); $pays = $xml->children()->children()->attributes(); $paysId = $pays['id']; $opt['url'] = $urlPrestashop.'api/stores?schema=synopsis'; $xml = $webService->get($opt); $resources = $xml->children()->children(); unset($xml->store->id); $resources->id_country = $paysId; unset($xml->store->id_state); unset($xml->store->hours); $resources->name = util::lang($do->getName()); $resources->address1 = $do->getAddress1(); $resources->address2 = $do->getAddress2(); $resources->postcode = $do->getCp(); $resources->city = $do->getCity(); $resources->latitude = $do->getLat(); $resources->longitude = $do->getLng(); $resources->phone = $do->getTel(); $resources->fax = $do->getFax(); $resources->note = util::lang($do->getDescription()); $resources->email = $do->getEmail(); $resources->active = $do->getVisible(); unset($xml->store->date_add); unset($xml->store->date_upd); $opt = array('resource' => 'stores'); $opt['postXml'] = $xml->asXML(); echo "<pre>";var_dump($opt);echo "</pre>"; $xml = $webService->add($opt); } catch (PrestaShopWebserviceException $e) { echo 'Erreur: <br />'.$e->getMessage(); } Et voici le résultat de mon dump <pre>array(2) { ["resource"]=> string(6) "stores" ["postXml"]=> string(943) "<?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <store> <id_country required="true" format="isUnsignedId">8</id_country> <name required="true" maxSize="128" format="isGenericName">Test</name> <address1 required="true" maxSize="128" format="isAddress"></address1> <address2 maxSize="128" format="isAddress"></address2> <postcode maxSize="12">56000</postcode> <city required="true" maxSize="64" format="isCityName">Vannes</city> <latitude maxSize="13" format="isCoordinate">47.658236</latitude> <longitude maxSize="13" format="isCoordinate">-2.7608470000000125</longitude> <phone maxSize="16" format="isPhoneNumber">0123456789</phone> <fax maxSize="16" format="isPhoneNumber">0123456789</fax> <note maxSize="65000" format="isCleanHtml"></note> <email maxSize="128" format="isEmail">[email protected]</email> <active required="true" format="isBool">1</active> </store> </prestashop> " } </pre> Auriez-vous une idée pour résoudre mon problème ? Merci Thomas Edited August 12, 2015 by tom56 (see edit history) Link to comment Share on other sites More sharing options...
tom56 Posted August 10, 2015 Author Share Posted August 10, 2015 Personne aurait une idée ? Merci Thomas Link to comment Share on other sites More sharing options...
loicmathaud Posted August 10, 2015 Share Posted August 10, 2015 La question est peut-être naïve, mais as-tu bien configuré les permissions de la clé utilisée pour le WebService ? Link to comment Share on other sites More sharing options...
tom56 Posted August 10, 2015 Author Share Posted August 10, 2015 Bonjour, Je viens de vérifier et j'ai bien les autorisations. Je comprends pas pourquoi il me dit une erreur Bad Request. Le XML me parait correct. Link to comment Share on other sites More sharing options...
tom56 Posted August 12, 2015 Author Share Posted August 12, 2015 Après pas mal de recherche, j'ai trouvé que cela venait de ma longitude qui était trop longue. Le mieux est d'activer le mode dev sur Prestashop pour voir les erreurs. Merci Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now