I have a question about the update of the status of an order. I create the basket using OCAPI and then I can successfully create an order with https://mydomain/dw/shop/v21_10/orders (POST) Order is fine. All data are there. Now the order has status CREATED and I want to change it to OPEN using the Shop API again. https://mydomain/dw/shop/v21_10/orders/MyOrderNumber (PATCH)
This is the message I receive
{"_v":"21.10","fault":{"arguments":{"statusFrom":"CREATED","statusTo":"OPEN"},"type":"StatusTransitionNotPossibleException","message":"The status transition from 'CREATED' to 'OPEN' isn't possible."}}
While if I try to make the same transition in Business Manager it works perfectly.
Anyone knows why?
The reason you can't transition the order from CREATED to OPEN is because there is a step in between.
Unfortunately, this is poorly documented in OCAPI docs, but we can see a clearer picture if we look at the DW API docs which explain in more detail.
A bit of background
First, notice the description of the
PATCH /orders/{order_no}
endpoint:Okay, so it follows the DW API rules. Let's take a look at the
Order.setStatus()
method (emphasis mine):So this is telling us that we can't move an order out of CREATED status except by either placing it or failing it. If we take a look at the documentation for
OrderMgr.placeOrder(order)
, it corroborates this:Now back to OCAPI
Now we know that OCAPI generally follows the same rules as the DW API when it comes to transitioning order statuses. (with the exception of CREATED -> FAILED)
So how do we go about placing an order with OCAPI?
With OCAPI, you can place an order by calling
POST orders/{order_no}/payment_instruments
which will trigger the following hooks:dw.order.hooks.PaymentHooks.authorizeCreditCard
ordw.order.hooks.PaymentHooks.authorize
, depending on the payment typedw.ocapi.shop.order.afterPostPaymentInstrument
On success of both those hooks, your order will now be in NEW status, and ready to be transitioned into OPEN.
This discussion is on the same topic, although talking about the controller context, not OCAPI.
So, even though business manager lets you get away with stuff (I assume so that admins can override things where necessary), in the context of OCAPI or a controller, the order has to follow the regular placement steps.