Magento – Unable to get order details using magento 2 rest api

magento2order-gridordersrest apisales-order

I have created an order in magento 2. And magento gave me this message

"Your order number is: 000000235. We'll email you an order
confirmation with details and tracking info."

Screen shot is also attached,
enter image description here

Then I tried to fetch the order details using rest api endpoint rest/V1/orders/235 in salesOrderRepositoryV1 on http://devdocs.magento.com/swagger/#/

My request as shown in screenshot,
enter image description here

but everytime i get this,

{
"message": "Requested entity doesn't exist"
}

Just for the reference screen shot of admin panel->sales->orders is also attached that i am fetching the details against the valid order id.

enter image description here

I investigated this isssue, here are some of my findings,

  1. This is not happening with all the orders.
  2. Its due to the difference between entity_id and increment_id in sales_order table.
  3. For most of the old orders(those i created earlier) everything is working fine but for most recent orders this issue is occuring(for which i have different entity_id and increment_id(magento gives us this id at success page)
  4. I need to pass in increment_id in rest/V1/orders/{id} but this endpoint point to entity_id in the sales_order table

Why i have difference in my entity_id and increment_id? In sales_order table i have same entity_id and increment_id for the first 165 orders(i.e entity_id = increment_id) then form entity_id 166 my increment_id became 179. Why this difference came in suddenly.

Can anyone please explain?

Best Answer

Its not mandatory that entity_id of sales_order table and increment_id of sales_order table are same.

entity_id field should be auto incremented ,so it may be differ when you delete any specific order manually and its used as foreign key in sales_order_item table to identify how many items each order have.

Meanwhile you must need to pass increment_id with orders api , But your url should be like this http://os.mydomain.com/index.php/rest/V1/orders/000000003

here 000000003 this is my increment_id

Then pass Authorization Bearer accesstoken in headers

It will works for all orders.

Related Topic