Loveitaly Posted April 18, 2016 Share Posted April 18, 2016 Hi all, I enabled the web service for my prestashop (version 1.6.0.9) website. I successfully used GET operation in XML and JSON format. Unfortunately POST and PUT worked for me only with payload in XML format, it seams impossible to me post data in JSON format, receiving an error message like {"errors":[{"code":3,"message":" SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found.....Does anyone know if it is a problem of my prestashop version? Can anyone help me to understand the problem?Thank you very much. Link to comment Share on other sites More sharing options...
Loveitaly Posted April 18, 2016 Author Share Posted April 18, 2016 I've just replaced all the files inside /classes/webservice/ with the latest ones as you suggested. But nothing changed, it seams that Prestashop webservice does not support POST/PUT operations if the payload is in JSON format. As using the previous files, if the payload is in XML format, everything works good (GET, POST and PUT operations). I have not checked the code, yet, but looking the error messages, I suppose that Prestashop webservice try to parse the payload using XML parser, even if in the url I set the parameter io_format=JSON. In the follow the complete error message: {"errors":[{"code":3,"message":" SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found (\/opt\/lampp\/htdocs\/loveitaly\/classes\/webservice\/backup\/WebserviceRequest.php, line 1455)"},{"code":3,"message":"[php Warning #2] SimpleXMLElement::__construct(): {\"contact\":{\"id\":\"\",\"email\":\"\",\"customer_service\":\"\",\"name\":\"cccc\",\"description\" (\/opt\/lampp\/htdocs\/loveitaly\/classes\/webservice\/backup\/WebserviceRequest.php, line 1455)"},{"code":3,"message":"[php Warning #2] SimpleXMLElement::__construct(): ^ (\/opt\/lampp\/htdocs\/loveitaly\/classes\/webservice\/backup\/WebserviceRequest.php, line 1455)"},{"code":127,"message":"XML error : String could not be parsed as XML\nXML length : 85\nOriginal XML : {\"contact\":{\"id\":\"\",\"email\":\"\",\"customer_service\":\"\",\"name\":\"cccc\",\"description\":\"\"[spam-filter]"}]} Link to comment Share on other sites More sharing options...
Loveitaly Posted April 18, 2016 Author Share Posted April 18, 2016 Yes, you were right about the cache, so I cleaned it, and I ran again the webservice with the proper latest files. Unfortunately I have the error anyway, here the error message from the correct new files, hoping you can help me: {"errors":[{"code":3,"message":" SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found (/opt/lampp/htdocs/loveitaly/classes/webservice/WebserviceRequest.php, line 1369)"},{"code":3,"message":"[php Warning #2] SimpleXMLElement::__construct(): {\"contact\":{\"id\":\"\",\"email\":\"\",\"customer_service\":\"\",\"name\":\"ioioioio\",\"descript (/opt/lampp/htdocs/loveitaly/classes/webservice/WebserviceRequest.php, line 1369)"},{"code":3,"message":"[php Warning #2] SimpleXMLElement::__construct(): ^ (/opt/lampp/htdocs/loveitaly/classes/webservice/WebserviceRequest.php, line 1369)"},{"code":127,"message":"XML error : String could not be parsed as XML\nXML length : 89\nOriginal XML : {\"contact\":{\"id\":\"\",\"email\":\"\",\"customer_service\":\"\",\"name\":\"ioioioio\",\"description\":\"\"[spam-filter]"}]} Link to comment Share on other sites More sharing options...
Loveitaly Posted April 19, 2016 Author Share Posted April 19, 2016 I tried, but it didn't work. Looking at the error, you can read: {"code":127,"message":"XML error : String could not be parsed as XML.... Of course the string can not be parsed as XML, because the string is in JSON format! The error point at the line: https://github.com/PrestaShop/PrestaShop/blob/1.6.1.x/classes/webservice/WebserviceRequest.php#L1369 The execution goes to the function saveEntityFromXml(...), so for sure something goes wrong, because the parsing should be done from JSON, should exist a function like "saveEntityFromJson"... Does anyone know if such situation is ok for prestashop webservice, in which we pass a Json object as payload for POST/PUT operation? Thank you very much. Link to comment Share on other sites More sharing options...
roband Posted April 19, 2016 Share Posted April 19, 2016 The PrestaShop webservice only supports JSON for GET operations. XML is needed for everything else. Link to comment Share on other sites More sharing options...
Loveitaly Posted May 6, 2016 Author Share Posted May 6, 2016 :o Never realized that... That explains why my favorite node.js package uses xml2js: https://www.npmjs.com/package/prestan Hi, I've seen the interesting node.js module Prestan you indicated. It would be nice to me using it from the client, but a solution like browserify is not the best for me. Can you tell me how you use it? Thank you, regards. 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