Jump to content

500 error when when updating current_state to certain values via REST


Recommended Posts

I'm using the PrestaShop REST system to update order statuses by changing the current_state field. While I can change the current_state field to certain values, other values cause the call to throw a 500 server error.


After some experimentation with the Order Statuses section on the backend, I determined that the issue has to do with a property for the order status itself, specifically the checkbox which reads "Set the order as shipped.". When the old order status does not have the box checked and the new order status does have it checked (or vice versa), then transitioning between the old and new order status will throw an error. If the old and new statuses both have the same checkbox value for the "Set the order as shipped." property, then transitioning between the states will not throw an error.


Any suggestions? I am using PrestaShop version:


NOTE: I understand that the shipping status cannot be set back to unshipped once it is shipped, so an error on that transition direction makes sense. But the unshipped to shipped transition should work, but isn't

Edited by gourmetchef (see edit history)
Link to comment
Share on other sites

Here is some C# code which replicates the issue. For context, order #4 is currently in state 2 (Payment accepted) and this is attempting to move it to state 4 (Shipped). It is failing with error code 500. Changing to state 3 (Processing in progress) works fine, as does moving it back to state 2.


            WebClient client = new WebClient();
            client.Credentials = new NetworkCredential("REDACTED", "");
            string xml = client.DownloadString("http://fibergourmet.life/api/orders/4");

            XmlDocument doc = new XmlDocument();

            XmlNode state = doc.SelectSingleNode("/prestashop/order/current_state");
            state.FirstChild.Value = "4";

            byte[] xmlBytes = Encoding.UTF8.GetBytes(doc.InnerXml.ToString());

            WebRequest req2 = WebRequest.Create("http://fibergourmet.life/api/orders");
            req2.Credentials = new NetworkCredential("REDACTED", "");
            req2.Method = "PUT";
            Stream postStream = req2.GetRequestStream();
            postStream.Write(xmlBytes, 0, xmlBytes.Length);

            HttpWebResponse resp2 = (HttpWebResponse)req2.GetResponse();

I've redacted our key, but if you contact me directly I'd be happy to share a temporary one so you can test it yourself. 

Edited by gourmetchef (see edit history)
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...