ferran_munoz Posted December 17, 2020 Share Posted December 17, 2020 (edited) Hi everyone. I want to update the state of my store (PS_ENABLE_SHOP) via API. When I call the update, respons me with 400 Bad Request and I don't know why. For example, in my website I have a checkbox to update the state. So, if my store is in Maintenance Mode, the check in the website is checked. When I change the state, I made an Ajax call to update the state. In the Controller I do this: $input = $request->all(); $state = $input['state']; $configurationName = 'PS_SHOP_ENABLE'; if($estado=='true'){ $configurationValue = new \SimpleXMLElement("<?xml version='1.0' standalone='yes'?>"); }else{ $configurationValue = 1; } // Start by checking if the configuration is present and get its ID $xml = $this->webService->get([ 'resource' => 'configurations', 'filter[name]' => '['. $configurationName . ']', ]); $configurationId = null; if ($xml->configurations->configuration->count() > 0) { $configurationId = (int) $xml->configurations->configuration[0]->attributes()['id']; } // Get the base XML, either a blank one or the existing one $configurationXml = $this->webService->get([ 'resource' => 'configurations', 'id' => $configurationId, ]); // Update values $configurationXml->configuration[0]->name = $configurationName; $configurationXml->configuration[0]->value = $configurationValue; $this->webService->edit([ 'resource' => 'configurations', 'id' => $configurationId, 'putXml' => $configurationXml->asXML(), ]); And the putXML (when I want to activate the site) is this: [[resource] => configurations, [id] => 28, [putXml] => <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <configuration> <id>28</id> <value>1</value> <name>PS_SHOP_ENABLE</name> <id_shop_group/> <id_shop/> <date_add>0000-00-00 00:00:00</date_add> <date_upd>2020-12-16 17:18:12</date_upd> </configuration> </prestashop> ] The error: App\PrestaShopWebserviceException: This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request App\PrestaShopWebservice->checkStatusCode(400) EDIT: Error detailed: [[status_code] => 400, [response] => <?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <errors> <error> <code><![CDATA[85]]></code> <message><![CDATA[Validation error: "Property Configuration->date_add is not valid"]]></message> </error> </errors> </prestashop> , [header] => HTTP/1.1 400 Bad Request Date: Thu, 17 Dec 2020 10:36:35 GMT Server: Apache/2.4.18 (Ubuntu) Strict-Transport-Security: max-age=31536000 Access-Time: 1608201395 X-Powered-By: PrestaShop Webservice PSWS-Version: 1.7.4.3 What's the problem? Thanks! Edited December 17, 2020 by ferran_munoz (see edit history) Link to comment Share on other sites More sharing options...
ferran_munoz Posted December 17, 2020 Author Share Posted December 17, 2020 I found the solution. If I unset the "date_add" field of the configuration object, returns 200 OK. unset($configurationXml->configuration[0]->date_add); Thanks! 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