Order status updates via rest api in magento 2

Order status updates via rest api in magento 2

July 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Order status updates via rest api in magento 2

Order Status Updates via REST API in Magento 2

Updating order status via the Magento 2 REST API is a common requirement for integrating third-party payment gateways or custom payment flows. In your case, you’re trying to set up a callback mechanism from a custom payment gateway that updates the order status after a successful transaction.

The WebAPI Configuration Your current webapi.xml configuration looks good. You’ve defined a route for /V1/orders/:id/statuses with a POST method that maps to the Setorderstatus method in your TarlanPay\TarlanPay\Api namespace. The anonymous resource indicates that this API endpoint is available without requiring authentication.

The Setorderstatus Interface The Setorderstatus interface defines a single public function status($id) which expects an order ID as a parameter and returns a string. This is the method that will be called when you make a POST request to the /V1/orders/:id/statuses endpoint.

The SetorderstatusModel Implementation Your SetorderstatusModel class implements both the Setorderstatus interface and the OrderRepositoryInterface provided by Magento’s Sales module. This allows you to load, save, delete, and search orders directly from this class.

The status Method Logic In your status method, you’re receiving JSON data from the POST request via file_get_contents(‘php://input’). You then decode this JSON using json_decode($tarlanResponse, true). If the response is not empty, you proceed to update the order’s state and status based on the ‘status’ value received from your custom gateway.

The Order State and Status Mapping Your switch statement maps the ‘status’ value from 0-6 to the corresponding Magento order states. For example, a status of 1 is mapped to the STATE_COMPLETE state and saves the order with that status.

The Issue: “Please provide payment for the order.” The error message you’re encountering, “Please provide payment for the order.”, suggests that the API is expecting an actual payment object in the request body, not just a JSON string containing the status update data. This could be because your method signature doesn’t match the expected format.

A suggested approach would be to create a new class that extends \Magento\Framework\Webapi\Rest\Response and override its getBody() method to manually return the required payment object in JSON format. You can then return an instance of this custom response from your status method.

Remember, when working with Magento 2’s web APIs, it’s crucial to follow the official API documentation and ensure that your methods are implemented in a way that adheres to Magento’s architectural guidelines.

Conclusion Updating order status via the REST API is a powerful feature of Magento 2. It allows for seamless integration with external payment gateways or custom payment flows. By properly configuring your webapi.xml, implementing the required interfaces, and handling the JSON data correctly, you can successfully update order statuses in real-time.

If you continue to encounter issues, I would recommend reviewing the API documentation found at https://adobe-commerce.redoc.ly/2.4.6-admin/tag/Sales%20Order#operation/salesOrderV1SavePut to ensure your implementation aligns with the expected format.

At Laravel Company, we specialize in helping businesses leverage Magento 2’s extensive capabilities, including its powerful web APIs. If you need further assistance or expert guidance on your specific use case, feel free to reach out!

Magento 2 API Extensions Configuration

Our network