3

Guys I want to update order status using API. I am using this api to change the order status but it's not working:

http://dev-jawed.com/index.php/rest/V1/orders

{
"status" : "Out-for-delivery",
"entity" : 1,
"items": {
        "order_id" : 1
  }
}

Any help will be appreciated.

6

If you look at the swagger api documents (either on your local machine at /swagger or at the devdocs). You should find the API V1/orders. If you are using your local version you will also have the button to try to calls direct from swagger which is nice for debugging. From looking through the documents you should be able to post something like the following to the api.

{
  "entity": {
    "entity_id": 0,
    "status": "string"
  }
}

Remember to replace the entity_id with the correct order id and the status with the status you would like to change to.

  • This will create problems with increment_id (as experienced in Magento 2.2) - order's increment id will be changed (from scope 1 1000000005, to scope 0 (admin) 000000008). – epson121 Jan 4 '18 at 12:43
  • @David Manners, is there any pattern that we can update staus more than one order in a single API call? – Jigar Dhaduk Jul 26 at 9:14
2

You can do this:

PUT /V1/orders/create

'entity' => [
                'entity_id'=> 1,
                'increment_id' => '000000001',
                'status'=> 'processing',
]

You currently (v 2.1.*) get the same result with calls:

PUT /V1/orders/create

https://github.com/magento/magento2/blob/24f2f071267f9e5ba0d5428b75fcbc76e6ef5b55/app/code/Magento/Sales/etc/webapi.xml#L64

POST /V1/orders

https://github.com/magento/magento2/blob/24f2f071267f9e5ba0d5428b75fcbc76e6ef5b55/app/code/Magento/Sales/etc/webapi.xml#L256

  • Is there any pattern that we can update staus more than one order in a single API call? – Jigar Dhaduk Jul 26 at 9:13
1

I think a better answer is to use the following api entry point

("/rest/V1/orders/{orderId}/comments", Method.POST);

pass the StatusHistory object in the post body, setting the appropriate fields to update the order status.

{
  "statusHistory": {
    "comment": "string",
    "createdAt": "string",
    "entityId": 0,
    "entityName": "string",
    "isCustomerNotified": 0,
    "isVisibleOnFront": 0,
    "parentId": 0,
    "status": "string",
    "extensionAttributes": {}
  }
}
  • FYI: not all of the fields are required, you can read which ones are required in the documentation – Sebastian Nov 15 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.