Search code examples
c#magentomagento-1.9magento-rest-api

Magento Change Order Status from REST API


I am 'communicating' with a Magento web app(version 1.9.2.2) via the REST API in a C# ASP.NET MVC application.

The application essentially acts as a backend order flow dashboard for pizzas. I need to display the latest orders and allow the user to check the items off as they are processed (among other things).

I am able to retrieve orders, products, customers etc; but need to be able to update the order status. From my research it seems that this can be achieved by adding an order comment.

That said, my questions are as follows:

  1. Is adding an order comment (thus updating the order status) only possible through the SOAP Service in Magento 1.9?
  2. If the above is true, how can I update the order status of a particular order using another secure approach?

Docs on REST API: http://devdocs.magento.com/guides/m1x/api/rest/Resources/Orders/order_comments.html


Solution

  • To anyone that may be facing the same issue, I discovered that it is not possible to update the order status (AKA add a sales order comment) via the REST API. You have to use the SOAP API and version 2 makes it easiest.

    Setup:

    1. In magento, create a SOAP Role and User
    2. Add the SOAP v2 API as a web reference to your Visual Studio project

    Code:

    public void UpdateOrderStatus(string orderIncrementId, string newStatus, string comment = "")
    {
        // Init service with uri
        var service = new MagentoSoap.MagentoService();
        // Login - username and password (soap api key) of the soap user
        string sessionId = service.login(Username, Password);
        // Update order status
        service.salesOrderAddComment(sessionId, orderIncrementId, newStatus, comment, 1, true);
    }