Cancel Order API

RetailByte
Shopify Partner
2 0 1

Couldn't find a post where this was properly answered.  At some point in the past I thought I was able to cancel an order 

Example resource:
https://xxxxxxxx.myshopify.com/admin/orders/298312803/cancel.json

My JSON Post:
{"order":{"amount":"35.26","restock":true,"reason":"other","email":true}}

The order looks to be cancelled in on shop’s web admin page, but I do not see the notification of restock or an email going out to the customer? 

However, it looks like I can accomplish what I need by adding some arguments to the resource.  Example:

https://xxxxxxxx.myshopify.com/admin/orders/298312803/cancel.json?&reason=other&restock=true&email=t...

But it fails when I try to add an amount and an argument.  The Argument approach seems like a work-around.  Anyone have some thoughts on my JSON post as to why it might not be working as expected?  

Thanks in advance.

Ken Kilar
Stacey7
New Member
7 0 0

I am interested in learning more about this as well.

0 Likes
Mohd_Imad
New Member
2 0 0

Hey Ken,

I was browsing around and found an article online which might help you, please have a look at this article:

http://shopifynation.com/shopify-tutorials/cancel-delete-order-shopify/

0 Likes
Mohd_Imad
New Member
2 0 0

Hey Ken,

I was browsing around and found an article online which might help you, please have a look at this article:

http://shopifynation.com/shopify-tutorials/cancel-delete-order-shopify/

0 Likes
Nick52
Shopify Expert
4 0 0

Hey Ken,

I was browsing around and found an article online which might help you, please have a look at this article:

http://shopifynation.com/shopify-tutorials/cancel-delete-order-shopify/

0 Likes
AngusPurcell
New Member
2 0 1

Hi Ken,

I think if you look at the documentation here https://shopify.dev/docs/admin-api/rest/reference/orders/order#cancel-2020-07

you can see that you don't need the {order: } wrapper in your json. If you send just the json:-

{"amount":"35.26","restock":true,"reason":"other","email":true}

then it should work as you are expecting I think.

Angus

0 Likes
Crayons
Excursionist
11 1 10

When cancelling an order, you do need to wrap the request body in "order". This has been an issue for several years now. The documentation does not appear to be accurate. If you try and call the endpoint exactly as it is described in the documentation, you'll receive a 422 Unprocessable Entity response from Shopify. I've reached out to the Shopify team, and I'll update with their reply.

0 Likes
Crayons
Excursionist
11 1 10

Shopify support has gotten back to me:

After doing some investigation, a bug was uncovered in that order cancel endpoint. The documentation is right in what the use should be, and there is no need to wrap the params within an order object. If you exclude the amount, the reason is set accordingly. The reason wrapping within an order object seems to work is because there is no root-level amount set. We are still investigation the issue with the authorisation not being voided, and I would get back to you once I have more information.


For reference, this is the request body I was passing that triggered the 422 Unprocessable response:

{
    "amount" => "100.00",
    "currency" => "CAD",
    "reason" => "fraud",
    "email" => false,
}

 

This is the request body that I was passing in order to get the endpoint to 'work'. Shopify indicated that this call worked because amount wasnt being passed as a parameter at the root level, and that wrapping the request in the order property effectively meant that shopify ignored the request body. In that scenario, Shopify was cancelling the order with the reason "other" by default.

{
    "order": {
        "amount": "100.00",
        "currency": "CAD",
        "reason": "fraud",
        "email": false,
    }
}

 

Lastly, as suggested, I have been able to get this endpoint working as described (partially), by unwrapping the request and removing the amount from the request body. My orders are now being cancelled with the appropriate reason set.

{
    "reason" => "fraud",
    "email" => false,
}

 

I'll post back again if they end up notifying me of a fix regarding the authorization voiding (amount property).

0 Likes
Crayons
Excursionist
11 1 10

As a final update, I have heard back from the Shopify team:

The issue seems to be one related to our docs, and it will be updated. The order cancel endpoint only attempts to refund any money that has been received from the customer when you include the amount field. For an authorisation, since no money is captured, there is no attempt to refund.

They have instead advised that cancellations should be done in two steps. First, to issue either a void or refund where applicable, using the transaction endpoint. Secondly, to then cancel the order using the order cancel endpoint as described previously.

0 Likes