0

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?

2

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.

  • I am doing the same for order 235(increment_id) as you can see in the screen shot number 2, but i am getting { "message": "Requested entity doesn't exist" }. I am doing exactly what you mentioned or am i doing something wrong? please refer to the screenshots attached with the question. – Abdul Moiz Aug 8 '17 at 9:35
  • No, like this, os.mydomain.com/rest/V1/orders/235. You can see screenshot number 2 for reference. What is this index.php in your url? – Abdul Moiz Aug 8 '17 at 9:44
  • I also tried os.mydomain.com/rest/V1/orders/000000235 and os.mydomain.com/index.php/rest/V1/orders/000000235 too, but it still says { "message": "Requested entity doesn't exist" }. I know the issue, /rest/V1/orders/ searches for order in sales_order table by entity_id. But it should search order by increment_id. To reproduce this issue, your increment_id and entity_id have to different. – Abdul Moiz Aug 8 '17 at 13:43
  • And i am sure no one deleted the records from my sales_order table manually, because my entity_id is consistent, as you said its auto increment so if some one would have deleted records from the table manually so i should have in consistent entity_id in sales_order table, but thats not the case. – Abdul Moiz Aug 8 '17 at 14:13
  • And leading zeros are not the issue, whether we include them or not, it does not matter, i have been using order id without leading zeros in various places, it works absolutely fine. This looks like a magento 2 REST API bug to me. But i am not sure how to reproduce it. Do you know how increment_id is generated in magento backend? – Abdul Moiz Aug 8 '17 at 14:15

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.