5

I'm trying to update the order status and add an order comment. I've found by looking at the Swagger reference that the best endpoint for this is likely:

/rest/V1/orders/9/comments

To which I'm posting the following array to:

    {
    "statusHistory": {
        "comment": "Transferred",
        "created_at": "2018-06-01  15:22:04",
        "entity_id": 9,
        "is_customer_notified": 0,
        "is_visible_on_front": 1,
        "status": "transferred"
    }
}

However, when I check the order in Magento Admin it's updating the order status to "transferred" correctly but isn't actually adding a comment to the order at all.

Magento Version: 2.2.3

2 Answers 2

6

For put comment in Magento 2 using API

url http://<magento-host>/rest/V1/orders/54/comments

Action type :: POST

Data

{
    "statusHistory": {
        "comment": "This is testing comment from API",
        "created_at": "2018-06-05  15:22:04",
        "parent_id": 54,
        "is_customer_notified": 0,
        "is_visible_on_front": 1,
        "status": "pending"
    }
}

Header

Authorization :: Bearer <Access Token>

output : it will return Boolean value.

Explanation

status is the order status, like - pending

order_id is the table increment id.
parent_id only has a value if you edit the order in the backend.
Here is how it works.

When you edit an order in the backend, the order is canceled and a new order is created, ending up with 2 orders.

In order to keep a link between these 2 orders, magento stores in the parent_id field of the second order the order_id of the original order.
That's why you will see on the second order view page in the backend a link to the original order.

3
  • So is there a way to update the status on an order without recreating the order? This behavior of recreating the order just to update a field makes little sense to me Commented Jun 30, 2020 at 14:55
  • @Adity Shah order state is not updating using this api. can u advise me how to add that? Commented Oct 26, 2021 at 13:05
  • Hi @NagarajuK - Can you please try PUT method? and please verify order_id and parent_id Commented Oct 27, 2021 at 16:59
0

I found the problem...

I was trying to pass what I thought the API was asking for which was the orders entity id. Instead I was supposed to pass the orders entity id as "parent_id".

Like so:

{
    "statusHistory": {
        "comment": "Transferred",
        "created_at": "2018-06-01  15:22:04",
        "parent_id": 9,
        "is_customer_notified": 0,
        "is_visible_on_front": 1,
        "status": "transferred"
    }
}

Why is there zero documentation on what these various fields mean? I've looked everywhere online and the best documentation I can find for the API is Swagger but it doesn't explain what the fields are.

3
  • I explained the input data field uses. Commented Jun 5, 2018 at 6:44
  • 1
    Wow! It works changing entity_id to parent_id. Terrible documentation by Magento and inconsistent API compared to other methods. Thanks for figuring that out.
    – Corgalore
    Commented Jul 12, 2018 at 3:19
  • @zaedred but order state is not changing. how do we specify order state in this API? Commented Oct 26, 2021 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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