cancel
Showing results for 
Search instead for 
Did you mean: 

How Cancel or Close an Order.

SOLVED
Highlighted

How Cancel or Close an Order.

I am having a similar problem to this post:

https://magento.stackexchange.com/questions/314427/how-to-cancel-or-close-an-order-that-has-been-inv...

 

Basically my cancel order functionality is no longer working.  I post the /V1/orders/{id}/cancel and it returns only "false".  We don't process a lot of cancellations but this was working when we built it 2 years ago.  

The order is paid for and in the processing state if that helps. 

 

If cancelling will not work is there a logical equivalent like refunding and closing the order? If so what are the API steps required? For example, call the Refund API at XX and then call the close order API at XXYY.

 

Thanks a bunch

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How Cancel or Close an Order.

Hi @stacy1712 

For refund You can use below rest API:

url : http://<base_url>/rest/V1/invoice/{invoiceId}/refund

Method : POST
Token: Admin token

request: 
{
  "items": [
    {
      "extension_attributes": {},
      "order_item_id": 0,
      "qty": 0
    }
  ],
  "isOnline": true,
  "notify": true,
  "appendComment": true,
  "comment": {
    "extension_attributes": {},
    "comment": "string",
    "is_visible_on_front": 0
  },
  "arguments": {
    "shipping_amount": 0,
    "adjustment_positive": 0,
    "adjustment_negative": 0,
    "extension_attributes": {
      "return_to_stock_items": [
        0
      ]
    }
  }
}

For cancel order:
Method: POST
Token: Admin token
URL : 

http://<base_url>/rest/V1/orders/<order_entity_id>/cancel

response : true

cancel_order.png

If issue resolve, please click on 'Kudos' & Accept as Solution!

View solution in original post

4 REPLIES 4
Highlighted

Re: How Cancel or Close an Order.

Hi @stacy1712 

For refund You can use below rest API:

url : http://<base_url>/rest/V1/invoice/{invoiceId}/refund

Method : POST
Token: Admin token

request: 
{
  "items": [
    {
      "extension_attributes": {},
      "order_item_id": 0,
      "qty": 0
    }
  ],
  "isOnline": true,
  "notify": true,
  "appendComment": true,
  "comment": {
    "extension_attributes": {},
    "comment": "string",
    "is_visible_on_front": 0
  },
  "arguments": {
    "shipping_amount": 0,
    "adjustment_positive": 0,
    "adjustment_negative": 0,
    "extension_attributes": {
      "return_to_stock_items": [
        0
      ]
    }
  }
}

For cancel order:
Method: POST
Token: Admin token
URL : 

http://<base_url>/rest/V1/orders/<order_entity_id>/cancel

response : true

cancel_order.png

If issue resolve, please click on 'Kudos' & Accept as Solution!

View solution in original post

Highlighted

Re: How Cancel or Close an Order.

So once an order reaches a certain state it can no longer be canceled and must be refunded?

It might be a good idea to make this issue a top search result for "canceling an order through Magento 2 API."  I have seen countless results that either has no answer or just general confusion on the topic.  Usually with a very robotic response that although correct does not answer the question someone was asking.  

 

Highlighted

Re: How Cancel or Close an Order.


@Bhanu Periwal wrote:

Hi @stacy1712 happy wheels

For refund You can use below rest API:

url : http://<base_url>/rest/V1/invoice/{invoiceId}/refund

Method : POST
Token: Admin token 

request: 
{
  "items": [
    {
      "extension_attributes": {},
      "order_item_id": 0,
      "qty": 0
    }
  ],
  "isOnline": true,
  "notify": true,
  "appendComment": true,
  "comment": {
    "extension_attributes": {},
    "comment": "string",
    "is_visible_on_front": 0
  },
  "arguments": {
    "shipping_amount": 0,
    "adjustment_positive": 0,
    "adjustment_negative": 0,
    "extension_attributes": {
      "return_to_stock_items": [
        0
      ]
    }
  }
}

For cancel order:
Method: POST
Token: Admin token
URL : 

http://<base_url>/rest/V1/orders/<order_entity_id>/cancel

response : true
If issue resolve, please click on 'Kudos' & Accept as Solution!


Thanks guys. It was helpful

Highlighted

Re: How Cancel or Close an Order.


@Bhanu Periwal wrote:

Hi @stacy1712 basketballlegends fun

For refund You can use below rest API:

url : http://<base_url>/rest/V1/invoice/{invoiceId}/refund

Method : POST
Token: Admin token

request: 
{
  "items": [
    {
      "extension_attributes": {},
      "order_item_id": 0,
      "qty": 0
    }
  ],
  "isOnline": true,
  "notify": true,
  "appendComment": true,
  "comment": {
    "extension_attributes": {},
    "comment": "string",
    "is_visible_on_front": 0
  },
  "arguments": {
    "shipping_amount": 0,
    "adjustment_positive": 0,
    "adjustment_negative": 0,
    "extension_attributes": {
      "return_to_stock_items": [
        0
      ]
    }
  }
}

For cancel order:
Method: POST
Token: Admin token
URL : 

http://<base_url>/rest/V1/orders/<order_entity_id>/cancel

response : true

cancel_order.png

If issue resolve, please click on 'Kudos' & Accept as Solution!


Your answer will really help a lot, such answers and topics are always needed, thank you.