Updating order status in Prestashop via webservice api

青春壹個敷衍的年華 提交于 2019-12-06 06:39:32

It seems that xml parameter has to be of type RequestBody. If not specified it is automatically set to type GetOrPost which is causing 'String could not be parsed as XML' error. I'm not sure how everything works but it seems that this is the solution to the problem.

RestRequest request;
request = new RestRequest("api/orders/" + orderID, Method.GET);
IRestResponse response = client.Execute(request);

XElement orderXML = XElement.Parse(response.Content);
XElement orderEl = orderXML.Descendants().FirstOrDefault();
orderEl.Element("current_state").Value = "10";    

request = new RestRequest("api/orders", Method.PUT);
request.AddParameter("xml", orderXML.ToString(), ParameterType.RequestBody);
IRestResponse response2 = client.Execute(request);

You can also use a .Net wrapper written by C# instead of sending and retrieving XML requests. It also let you upload and change images which is a bit tricky using plain XML and http requests. It is called PrestaSharp.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!