Order Cancel API

Highlighted
New Member
5 0 0

I can't get a correct response from the Order Cancel API on shopify.

 

I can retrieve the details of the order I want to cancel by doing a GET in the following format:

 

https://<mystore>myshopify.com/admin/api/2020-01/orders/<order number>.json

This returns correctly in my code and correctly using 'Postman' to mock the calls.

 

But when I try to call the order cancel (as a POST) on the same order number (see below):

 

https://<mystore>myshopify.com/admin/api/2020-01/orders/<order number>/cancel.json

 

In my code I'm getting a 422 error and in Postman I get:

 

<html>

<body>
  <noscript>
    <a
  </noscript>

  <script type="text/javascript">
    window.location = "https:\/\/app.shopify.com\/services\/login\/identity?destination_uuid=8011e685-2663-4b3c-8df5-08624d743d87\u0026enforce_merge=true\u0026merge_ignore_postponed=false\u0026prompt=merge\u0026return_to=https%3A%2F%2Fapp.shopify.com%2Fservices%2Flogin%2Fidentity_callback%3Ffrom_signup%3Dfalse%26locale%3Den%26shop_name%3DSF%2BDEV%2B%253A%2BDr%2BFertility%26state%3DRVUQJ5Rh9Fhvmm32TQ7vu01qD2Pskdog-UFY4LQ9l4cZjPuxyShQp7-ay6SRsclLmp3wLTY6upTKrUjjtNnOxRJjBMhqiHpjw87XyVeITSViOJoyfWw4v6Dl5mS73B-xCABrDfyb-zaMhSeuGSrFMe6tSEEfFrNLAnIewywNW7dG5paBoJSyuLDw9pwJVaegVKryaLtz2f8QAtylYnqVFHOVu-tI3TZuEzoWcGUElpIDnOi21Yo7sMuJbm00JFGs\u0026ui_locales=en\u0026ux=shop";
  </script>
</body>

</html>

 

0 Likes
Highlighted
New Member
5 0 0

The X-Request-Id for this call is dc3c6259-872d-4dec-9cca-88227d00a4b3

0 Likes
Highlighted
New Member
5 0 0

Answering my own post from previous post:

 

Shopify Expert => "If you're getting the HTML login page response I can make a fairly strong assumption that you're sending cookies in your POST. The server will block any change request that includes header cookies.

You'll be able to test this easily in the desktop version of Postman since that tool will let you remove/include header cookies". 

 

The above is correct, I removed the cookies and then Postman now returns the same error as my code which is a 422 - Unprocessable Entity, with the error message of "

 "error": "Amount must be less than net payment"
 
However, here is the problem, the amount is correct.  The live code I have running against our live shopify store against API 2019-04 works fine.  The test code against API 2020-01 is throwing this error.  
 
***** My question is:  Are we seeing this error because the order is on our test shopify site and the order was placed through the 'bogus' payment gateway???? *****
0 Likes
Highlighted
New Member
5 0 0

Answering my own post for anyone else who comes across this.

 

So, I am running a test and a live shopify account.  I'm running the same code against both sites for cancelling an order, the live site works and the test site doesn't.    I've bought the same product, on both sites.    Turns out, if you are using a bogus gateway for your test system you can only cancel an order with a refund if you set the refund to be 0.00 (I'm presuming that shopify is checking this against the total_spent variable?).

 

So if you run:

https://<my shopify store>/admin/api/orders/<order no>/cancel.json

with the following <body> 

{ "note":"this is a cancel test", "email":"true","amount":"0.00","currency":"GBP"}

 

Against an order that has been paid on a bogus gateway, then it will work. 

However, even if you put a penny in the amount, it will fail with a 422 error and Amount must be less than net payment error.  Regardless of what the total_price on the product is.  So Shopify does not handle 'dummy refunds' in the way you would expect.

 

 

0 Likes